How does WordPress convert raw data from the database to a readable format in the_content function?

I've noticed that it applies the_content filter, but what does the_content filter do?

3 Answers 3


the default filters are set in /wp-includes/default-filters.php;

for 'the_content' this is from line 135:

add_filter( 'the_content', 'wptexturize'        );
add_filter( 'the_content', 'convert_smilies'    );
add_filter( 'the_content', 'convert_chars'      );
add_filter( 'the_content', 'wpautop'            );
add_filter( 'the_content', 'shortcode_unautop'  );
add_filter( 'the_content', 'prepend_attachment' );

to trace the individual functions, you could try and use http://phpxref.ftwr.co.uk/wordpress/nav.html?_functions/index.html then follow the links...


Missed one (wp-includes/default-filters.php, line 102):

// Format WordPress
foreach ( array( 'the_content', 'the_title' ) as $filter )
    add_filter( $filter, 'capital_P_dangit', 11 );

All filters are stored in the global $wp_filter variable. You can inspect that variable to see which functions are bound to a certain filter.

global $wp_filter;

To exactly understand the array that gets outputted, knowing how the $wp_filter variable is built up helps a lot. This line is from the source of the add_filter() function:

$wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);

but what does the_content filter do?

The content_filter enables you to return custom content before or after the content.

2 very basic practical examples of using the_content filter in a custom function are as follows:

This example returns custom content before the content

 add_filter( 'the_content', 'return_before_content' ); 

 function return_before_content( $content ) { 

    if ( is_singular('post')) {

        $before_content = '<p>Text Returned Before the_content</p>';

        $content = $before_content . $content;


    return $content;

This example returns custom content after the content

 add_filter( 'the_content', 'return_after_content' ); 

 function return_after_content( $content ) { 

    if ( is_singular('post')) {

         $after_content = '<p>Text Returned After the_content</p>';

        $content = $content . $after_content;


    return $content;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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