0

I'm trying to write a simple text replacement plugin, but I'm having an issue that I can't figure out how to troubleshoot.

This is the test plugin I'm using as a starting point. It works fine on one Wordpress installation running locally (installation A), but on another local installation (installation B), it has no effect on the post content. It's strange because installation b is working fine and I don't see any other bugs/issues.

<?php
/*
 * Plugin Name: Thanks for Reading
 */
add_filter( 'the_content', 'tfr_the_content' );

function tfr_the_content( $content ) {
  return $content . '<p>Thanks for Reading!</p>';
}

Any thoughts on how to troubleshoot this?

6
  • The only reason I can think of now is that you are using the_excerpt on your installation B Jun 18, 2014 at 17:24
  • Interesting. I was using get_the_content() in both installations, but when I tried changing it to get_the_excerpt() on installation b, it's working! How can I get it to work on get_the_content()? PS - thanks for the help so far!! Jun 18, 2014 at 17:35
  • Are both installations exactly the same, running the same theme, version and plugins Jun 18, 2014 at 17:39
  • Unfortunately they're both very different. I was only using installation A to verify that the plugin code wasn't the problem. So I guess my main question now is why does the plugin work on get_the_excerpt() but not get_the_content()? Jun 18, 2014 at 17:44
  • 1
    Found the answer. Apparently plugins don't work on get_the_content(), so I used the output buffering example below. I found it here: stackoverflow.com/questions/15970625/… ob_start(); the_content(); $newContent = ob_get_clean(); Jun 18, 2014 at 18:48

1 Answer 1

1

Found the answer. Apparently plugins don't work on get_the_content(), so I used the output buffering example below. I found it here

ob_start();
the_content();
$newContent = ob_get_clean();

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.