Is it possible to change the contents of “the_content()”?

I have moved a blog over to wordpress and I’ve used a lot of DOMDocument, xpath, regex and other methods to scrub the text.

This means that the_content(); is no longer the content and I’m using my own function ‘stripped_content();’ to echo out my stuff.

Read More

I have a plugin that looks for the_content(); and puts some social media buttons beneath it, but obviously my posts no longer use it.

So how can I make the_content(); my new content?

Related posts

1 comment

  1. Add a filter to the_content and put your code in there so you don’t need your custom content function:

    function wpa_content_filter( $content ) {
        // run your code on $content and
        return $content;
    }
    add_filter( 'the_content', 'wpa_content_filter' );
    

    You may need to adjust priority to run your filter before or after others:

    // high priority, run early
    add_filter( 'the_content', 'wpa_content_filter' 1 );
    
    // low priority, run late
    add_filter( 'the_content', 'wpa_content_filter' 999 );
    

Comments are closed.