How to display the content from WordPress page or post

Posted on: July 21st, 2022
By: Tadeo Martinez

if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile;
endif;

And if you’d like to display the content conditionally only if there’s content, here’s what you do

if(get_the_content()){
echo '<section>';

if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile;
endif;

echo '</section>';

}

Have any questions or comments? Write them below!


Leave a Reply

Your email address will not be published. Required fields are marked *