#46865 closed defect (bug) (invalid)
get_the_excerpt() can have side effect of outputting HTML when excerpt is empty
| Reported by: | tmdesigned | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Posts, Post Types | Version: | 5.1 |
| Severity: | normal | Keywords: | close |
| Cc: | Focuses: |
Description
get_the_excerpt() returns a post's excerpt, as opposed to the_excerpt() which displays it.
However, if the excerpt is empty, wp_trim_excerpt attempts to create it from the content, and this can cause HTML to be displayed, even if the result of get_the_excerpt is never used.
Specifically related to line breaks, which it sees as \n, it can cause <br> and <p> tags to be added to the markup. This in turn can confuse output, such that a closing </p> tag may be isolated without a matching <p> tag, thus breaking the HTML structure and forcing browsers to try and compensate.
The culprit seems to be that the_content filter is run on the excerpt (formatting.php, wp_trim_excerpt()). This is well-intentioned but has, among other things, autop.
Proposed fix: Similar to get_the_content(), I believe get_the_excerpt() should not run through that filter.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Possibly related #36934 and #45267