#46865 closed defect (bug) (invalid)
get_the_excerpt() can have side effect of outputting HTML when excerpt is empty
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.1 |
Component: | Posts, Post Types | Keywords: | close |
Focuses: | Cc: |
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.
Possibly related #36934 and #45267