WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#40908 closed defect (bug) (invalid)

HTML Paragraph Tags are omitted in the return value of get_the_content().

Reported by: digitronixweb Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: template Cc:
PR Number:

Description

Hello,

I noticed a minor bug regarding the default Wordpress Post & Page content field.

When getting the value of the default Wordpress content WYSIWYG field using the following snippet:

<?php

if(have_posts()) { 
    while(have_posts()) {
        the_post(); 
  
        the_content();
    }
}

The correct HTML formatting is output as expected.

If instead I use the following:

<?php

if(have_posts()) { 
    while(have_posts()) {
        the_post(); 
  
       echo get_the_content();
    }
}

HTML tags persist in the resulting value, however, paragraph tags are seemingly omitted from the value return from the call to get_the_content.

Thanks!

Change History (2)

#1 @ocean90
2 years ago

  • Component changed from Editor to Posts, Post Types
  • Focuses ui administration removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version 4.7.5 deleted

Hello @digitronixweb, welcome to WordPress Trac!

get_the_content() is not a direct replacement for the_content(). Adding paragraphs to the content is handled by the the_content filter which only exists in the_content().

To get the same content as the_content() you have to use apply_filters( 'the_content', get_the_content() ).

#2 @digitronixweb
2 years ago

Ah I see, my apologies!

Thanks for the quick feedback, it's really appreciated!

Note: See TracTickets for help on using tickets.