0

What does this statement actually do?

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

It follows only these ones:

$text = get_the_content('');

$text = strip_shortcodes( $text );

What filter(s) is applied here?

  • Your question is not clear, can you please add some more explanation to it. – Maruti Mohanty Nov 12 '13 at 12:10
2

The usual way to show the post content, within the loop, is to use:

the_content();

that will echo the output, not return it like get_the_content().

But since you want to assign it to the $text variable, you use:

$text = get_the_content('');

but then the the_content output filter is not applied.

That's the reason why you have this line:

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

because it will filter $text through all the callbacks registered to the the_content filter.

You can always learn a lot from reading the source directly. The the_content() function is defined as:

function the_content( $more_link_text = null, $strip_teaser = false) {
        $content = get_the_content( $more_link_text, $strip_teaser );
        $content = apply_filters( 'the_content', $content );
        $content = str_replace( ']]>', ']]>', $content );
        echo $content;
}

You can check all the callbacks registered to the the_content filter with:

add_action( 'wp_footer', function(){
   printf( '<h3>Debug:</h3><pre>%s</pre>', 
            print_r( $GLOBALS['wp_filter']['the_content'], TRUE ) ); 
});

This will give you output at the bottom of your page, similar to this:

<h3>Debug:</h3>
<pre>Array
( 
    [10] => Array
        (
            [wptexturize] => Array
                (
                    [function] => wptexturize
                    [accepted_args] => 1
                )

            [convert_smilies] => Array
                (
                    [function] => convert_smilies
                    [accepted_args] => 1
                )

            [convert_chars] => Array
                (
                    [function] => convert_chars
                    [accepted_args] => 1
                )

            [wpautop] => Array
                (
                    [function] => wpautop
                    [accepted_args] => 1
                )

            [shortcode_unautop] => Array
                (
                    [function] => shortcode_unautop
                    [accepted_args] => 1
                )

            [prepend_attachment] => Array
                (
                    [function] => prepend_attachment
                    [accepted_args] => 1
                )

        )

    [11] => Array
        (
            [capital_P_dangit] => Array
                (
                    [function] => capital_P_dangit
                    [accepted_args] => 1
                )

            [do_shortcode] => Array
                (
                    [function] => do_shortcode
                    [accepted_args] => 1
                )
        )
)

where the array key numbers are the filter priorites.

| improve this answer | |

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.