0

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(); ?>
</section>

With this:

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

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.

Thanks!

2

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' ); ?>
</section>
| improve this answer | |
  • First method worked! I am wondering, do you recommend one or the other as better? Thanks so much. – Jennifer Michelle May 8 '13 at 12:47
  • ok great, if you are using some other the_content filters you might consider the latter approach. – birgire May 8 '13 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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