Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#46865 closed defect (bug) (invalid)

get_the_excerpt() can have side effect of outputting HTML when excerpt is empty

Reported by: tmdesigned's profile tmdesigned 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.

Change History (4)

#1 @tmdesigned
6 years ago

Possibly related #36934 and #45267

#2 @tmdesigned
6 years ago

I have been unable to replicate on trunk. I will do further testing.

#3 @tmdesigned
6 years ago

  • Keywords close added
  • Resolution set to invalid
  • Status changed from new to closed

I believe this is actually a PHP error being generated in the_content filters, as disabling xdebug/wp_debug resolved the issue. As such I am closing the ticket.

#4 @SergeyBiryukov
6 years ago

  • Component changed from General to Posts, Post Types
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.