1

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.

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?

4

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 );
  • Thanks, so instead of this $html = mb_convert_encoding($post->post_content, 'HTML-ENTITIES', "UTF-8"); would I now do this $html = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8");? and do I return it with $doc->saveHTML(); return $content; and then just call the_content();? – UzumakiDev Jan 8 '14 at 18:27
  • 3
    you need to return whatever contains the final processed content - if it's the $html var, then you return $html. then you can just use the_content() in your template. – Milo Jan 8 '14 at 18:37

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.