WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 6 down vote accepted

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 );
share|improve this answer

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);
share|improve this answer

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;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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