• Resolved krimsly

    (@krimsly)


    Greetings fellow theme coders,

    After hunting around the forums, I discovered that some functions that return post or page content call apply_filters() so that any short tags are parsed and turned into HTML. But, other functions do not apply the filters so you have to call it yourself, like this:

    $content = apply_filters('the_content', $content);

    The WP docs has a cryptic description of what might happen with this behavior in the future (see below). So, I’m wondering what will happen to my theme if I’m calling apply_filters() but that function gets called automatically by WP in a future version. Any thoughts or suggestions?

    Thanks

    -NorthK

    (From
    https://codex.www.ads-software.com/Template_Tags/the_content#Alternative_Usage):

    “Please note! get_the_content will not have the following done to it and you are advised to add them until the core has been updated:

    <?php
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • velojet

    (@velojet)

    krimsly:

    So, I’m wondering what will happen to my theme if I’m calling apply_filters() but that function gets called automatically by WP in a future version. Any thoughts or suggestions?

    Simple answer, NorthK: nothing. You can confirm that for yourself just by duplicating those two lines in your code. The only effect will be redundant processing.

    (I ran into the same problem as you when I discovered that my page template – which uses get_the_content() – wasn’t interpreting shortcodes. Eventually, I discovered the same reference in the codex as you did.)

    John V

    Thread Starter krimsly

    (@krimsly)

    Thanks John V.

    Thanks alot, this was my problem also and causing problems with shortcodes. However, your code above may not be correct? The codex page you reference has a different str_replace which includes: &-g-t-; – which I can’t make appear in this post, it gets stripped out, probably as it did in your post.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘apply_filters(); call it or don’t?’ is closed to new replies.