SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Guru
    Join Date
    Jan 2010
    Posts
    638
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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


    Thanks,

    Chris

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,617
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    The first line is "the loop" in wordpress: The Loop WordPress Codex

    The other function is here: Function Reference/remove filter WordPress Codex
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Guru
    Join Date
    Jan 2010
    Posts
    638
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    FF,
    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.

    Thanks,

    Chris

  4. #4
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,617
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    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.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  5. #5
    SitePoint Guru
    Join Date
    Jan 2010
    Posts
    638
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks

  6. #6
    Non-Member
    Join Date
    Apr 2004
    Location
    Miami, FL, USA
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol.... for some reason, I feel the function should be called teh_post();

    naming convention fail.

  7. #7
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Chris77 View Post
    FF,
    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.

    Thanks,

    Chris
    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.
    Saul

  8. #8
    SitePoint Guru
    Join Date
    Jan 2010
    Posts
    638
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.
    Description: Changes double line-breaks in the text into HTML paragraphs (<p>...</p>).

    WordPress uses it to filter the content and the excerpt.
    Usage

    <?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' );




    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?

    Thanks,

    Chris

  9. #9
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.
    Saul

  10. #10
    SitePoint Guru
    Join Date
    Jan 2010
    Posts
    638
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Daemon,

    Now I'm wondering if I should take
    remove_filter( 'the_excerpt', 'wpautop' );
    out.

    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,


    Chris

  11. #11
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Chris77 View Post
    or the double spacing after </p>?
    It means changing this:

    Code:
    example paragraph 1
    
    example paragraph 2
    to this:

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

    Quote Originally Posted by Chris77 View Post
    My site does double space after </p> - despite having the hook/filter/function:
    remove_filter( 'the_excerpt', 'wpautop' );
    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.
    Saul

  12. #12
    SitePoint Guru
    Join Date
    Jan 2010
    Posts
    638
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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?

    Thanks

    Chris

  13. #13
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Don't comment out the the_content(); just remove_filter('the_content', 'wpautop');
    Saul

  14. #14
    SitePoint Guru
    Join Date
    Jan 2010
    Posts
    638
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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,

    Chris


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •