WordPress插件:在the_content中找到<! - more - >

Mar*_*ing 0 wordpress filter wordpress-plugin

我正在编写一个过滤the_content的WordPress插件,我想使用<!--more-->标签,但它似乎已经被它剥离了.这看起来不是过滤器,而是WordPress工作方式的功能.

我当然可以从数据库中重新加载已经加载的内容,但这听起来可能会引起其他麻烦.有没有什么好方法让我获得原始内容而不<!--more-->删除?

Fra*_*mer 6

在您的插件运行时,机会<!--more-->已被转换为<span id="more-1"></span>

这是我在我的插件中使用的,它在标记之后立即注入一些标记<!--more-->:

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;
}
Run Code Online (Sandbox Code Playgroud)