views:

558

answers:

2

I'm writing a WordPress plugin that filters the_content, and I'd like to make use of the <!--more--> tag, but it appears that it has been stripped out by the time it reaches me. This appears to be not a filter, but a function of the way WordPress works.

I could of course resort to reloading the already-loaded content from the database, but that sounds like it might cause other troubles. Is there any good way for me to get the raw content without the <!--more--> removed?

+1  A: 

Looks like you were answered over on WordPress.org - did that solution work for you?

McGirl
Sorry, feels like this "answer" should be a comment but I don't have enough reputation points to comment on your original post. :)
McGirl
Have some rep then :)
Marcus Downing
I suppose it's an option - the $post contains the original post before it was processed, and if I revert to that then I can use both the <!--more--> and the unshortened post. But I worry about what other processing this may bypass?
Marcus Downing
Thanks Marcus!! Glad you found your answer.
McGirl
+2  A: 

Chances are, by the time your plugin runs, <!--more--> has been converted to <span id="more-1"></span>

This is what I use in my plugin, which injects some markup immediately after the <!--more--> tag:

add_filter('the_content', 'inject_content_filter', 999);

function inject_content_filter($content) {
  $myMarkup = "my markup here<br>";
  $content = preg_replace('/<span id\=\"(more\-\d+)"><\/span>/', '<span id="\1"></span>'."\n\n". $myMarkup ."\n\n", $content);
  return $content;
}
Frank Farmer
So it does. I hadn't noticed that!Now I just need to find out how to stop it removing the section after the more, when it's on listing pages.
Marcus Downing