Filter WordPress插件:查找<--更多-->;在内容中
我正在写一个WordPress插件,它过滤内容,我想使用Filter WordPress插件:查找<--更多-->;在内容中,filter,wordpress,Filter,Wordpress,我正在写一个WordPress插件,它过滤内容,我想使用标签,但是当它到达我这里时,它似乎已经被删除了。这似乎不是一个过滤器,而是WordPress工作方式的一个功能 我当然可以从数据库中重新加载已经加载的内容,但这听起来可能会引起其他问题。有没有什么好方法可以让我在不删除的情况下获取原始内容?当你的插件运行时,已经转换成 这就是我在插件中使用的,它在标记之后立即注入一些标记: add_filter('the_content', 'inject_content_filter', 999); f
标签,但是当它到达我这里时,它似乎已经被删除了。这似乎不是一个过滤器,而是WordPress工作方式的一个功能
我当然可以从数据库中重新加载已经加载的内容,但这听起来可能会引起其他问题。有没有什么好方法可以让我在不删除
的情况下获取原始内容?当你的插件运行时,
已经转换成
这就是我在插件中使用的,它在
标记之后立即注入一些标记:
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;
}
add_filter('the_content','injection_content_filter',999);
函数注入内容过滤器($content){
$myMarkup=“此处我的标记
”;
$content=preg_replace(“//”,“.”\n\n“$myMarkup.”\n\n“,$content);
返回$content;
}
您可以使用以下代码:
这个!is_single()将避免在查看帖子页面中显示更多链接
add_filter('the_content', 'filter_post_content');
function filter_post_content($content,$post_id='') {
if ($post_id=='') {
global $post;
$post_id = $post->ID;
}
// Check for the "more" tags
$more_pos = strpos($filtered_content, '<!--more-->');
if ($more_pos && !is_single()) {
$filtered_content = substr($filtered_content, 0, $more_pos);
$replace_by = '<a href="' . get_permalink($post_id) . '#more-' . $post_id
. '" class="more-link">Read More <span class="meta-nav">→</span></a>';
$filtered_content = $filtered_content . $replace_by;
}
return $filtered_content;
}
add_filter('the_content'、'filter_post_content');
函数filter\u post\u content($content,$post\u id=''){
如果($post_id==''){
全球$员额;
$post_id=$post->id;
}
//检查“更多”标签
$more_pos=strpos($filtered_content');
如果($more_pos&&!is_single()){
$filtered\u content=substr($filtered\u content,0,$more\u pos);
$replace_为='';
$filtered_content=$filtered_content.$replace_by;
}
返回$filtered\u内容;
}
基于我解决了在生成的更多标签后添加缩略图的问题(确实如此。我没有注意到!现在我只需要找出如何阻止它在更多之后删除该部分,当它出现在列表页面上时。看起来你已经被回答过了-该解决方案对你有效吗?我想这是一个选项-$post在处理之前包含原始帖子,如果我恢复到该选项,那么我可以使用它和未分类的帖子。但我担心这可能会绕过哪些其他处理?
// change more tag to post's thumbnail in single.php
add_filter('the_content', function($content)
{
if(has_post_thumbnail())
{
$post_thumbnail = get_the_post_thumbnail(get_the_ID(), 'thumbnail', array('class'=>'img img-responsive img-thumbnail', 'style'=>'margin-top:5px;'));
$content = preg_replace('/<span id\=\"(more\-\d+)"><\/span>/', '<span id="\1"></span>'.$post_thumbnail, $content);
}
return $content;
}, 999);