[wp-trac] [WordPress Trac] #46865: get_the_excerpt() can have side effect of outputting HTML when excerpt is empty

WordPress Trac noreply at wordpress.org
Tue Apr 9 17:58:48 UTC 2019


#46865: get_the_excerpt() can have side effect of outputting HTML when excerpt is
empty
--------------------------+-----------------------------
 Reporter:  tmdesigned    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46865>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list