I removed automatic formatting in my WP site by adding this to functions.php:

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

Now I need to add it back into one section only. On page.php, I want to replace the_content with wpautop formatted content.

I replaced this:

<section class="post-content clearfix" itemprop="articleBody">
    <?php the_content(); ?>

With this:

<section class="post-content clearfix" itemprop="articleBody">
        $c = the_content();
        $format_c = wpautop( $c, false );
        echo ($format_c);

Unfortunately it is not adding paragraph tags here. Can anyone help me to add paragraph tags only at this location in my theme? I do not want them in the page custom templates or any of the posts.


1 Answer 1


Please try this

$c = get_the_content();

instead of:

$c = the_content(); 

since the_content() will echo the content instead of returning it.

Or try this

<section class="post-content clearfix" itemprop="articleBody">
    <?php  add_filter( 'the_content', 'wpautop' ); ?>
    <?php the_content(); ?>
    <?php  remove_filter( 'the_content', 'wpautop' ); ?>
  • First method worked! I am wondering, do you recommend one or the other as better? Thanks so much.
    – Jen
    May 8, 2013 at 12:47
  • ok great, if you are using some other the_content filters you might consider the latter approach.
    – birgire
    May 8, 2013 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.