PHP Code Meaning

Have any idea what the purpose of this code is?

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php remove_filter(‘the_content’, ‘wpautop’); the_content(); ?>

Seems very repetitive



The first line is “the loop” in wordpress: The Loop « WordPress Codex

The other function is here: Function Reference/remove filter « WordPress Codex

I read there that, “This function removes a function attached to a specified filter hook.” But I also read “Hooks are provided by WordPress to allow your plugin to ‘hook into’ the rest of WordPress;”

I can’t figure out if the hooks are optional or essential. I would guess essential, unless you’re not using any plugins, which I’m not. So I guess I could take this line (the second line at the top) out.



You will need the_content().

That displays the content of a post.

I’m not exactly sure what the remove_filter() function is trying to accomplish, or if changes will impact anything else.

I’m going to move this over to the wordpress forum, as you might get a more specific answer there.


lol… for some reason, I feel the function should be called teh_post();

naming convention fail.

Using hooks is optional. In your example it removes the ‘wpautop’ function from the ‘the_content’ hook, which was probably attached somewhere else. That’s not default behavior, there’s something specific your theme is doing with the post output.

PHP Daemon.
Either your saying it removes the hook from the hook or it removes the filter from the hook. Wouldn’t it be easier to just remove the hook? How do I do that?

On a wordpress page it says.
[COLOR=“Blue”]Description: Changes double line-breaks in the text into HTML paragraphs (<p>…</p>).

WordPress uses it to filter the content and the excerpt.

<?php wpautop( $foo, $br ); ?>

Disabling The Filter

Some people choose to disable the wpautop filter from within their theme’s functions.php:

remove_filter( ‘the_content’, ‘wpautop’ );
remove_filter( ‘the_excerpt’, ‘wpautop’ );[/COLOR]

Why wouldn’t I want to disable the filter by finding
<?php wpautop( $foo, $br ); ?>

and deleting it? Where would wpautop( $foo, $br ) be located?



Because wpautop is a built-in WordPress function. If you want to remove it, you have to hack WP core files. Then all new updates would reverse your changes every time.

PHP Daemon,

Now I’m wondering if I should take
remove_filter( ‘the_excerpt’, ‘wpautop’ );

Is a double line break:
<br /><br /> (I don’t think so.)

or the double spacing after </p>?

My site does double space after </p> - despite having the hook/filter/function:
remove_filter( ‘the_excerpt’, ‘wpautop’ );

Makes me wonder if code elsewhere has already stopped the core code for double line breaks.

Thanks for the help,


It means changing this:

example paragraph 1

example paragraph 2

to this:

<p>example paragraph 1</p>
<p>example paragraph 2</p>

Line breaks in source code? Does it matter?

If your post content already contains <p> tags, removing the filter won’t remove the tags. In fact, if there are double line breaks after </p> tags, it means the wpautop didn’t work as it tidies up the newlines whether there are <p> tags or not.

PHP Daemon,
That’s what I was thinking. My guess is that it’s not working because the programmer placed it in index.php instead of funtions.php.

First I put a # in front of
<?php remove_filter(‘the_content’, ‘wpautop’); the_content(); ?>
and checked affect on my site, no problems.

Then I took
#<?php remove_filter(‘the_content’, ‘wpautop’); the_content(); ?>

out and checked affect on my site and the removal affected my site and the text (what I was writig about on my site) disappered, so I put it back in (didn’t keep the #).

Any thoughts?



Don’t comment out the the_content(); just remove_filter(‘the_content’, ‘wpautop’);

PHP Daemon,
I’ll have to leave it in. I have indenting on my paragraphs. When I take that piece of code out, reference links I have after paragraphs are indented. It looks terrible, so I’ll have to leave it in. But I learned a few things. It’s strange how commenting it out had no effect.

Thanks for the help,