我试着在每个帖子中寻找生成SEO标题的代码,以删除标题末尾的'-‘。通常,当标题显示在浏览器上时,在标题和浏览器之间已经有了'-‘。
Ex: title - chrome, title - firefox, title - safari但就目前而言,我认为:
title - - chrome, title - - firefox, title - - safari在帖子的标题中看起来相当丑陋。我曾尝试在class- effect tend.php中删除它,但似乎没有效果。那么,我该如何删除它呢?或者应该在获取帖子的标题时删除它,并在每个帖子中生成以放入SEO标题字段
发布于 2014-03-25 17:12:11
将下面的脚本放在header.php中wp_head()函数之后或header.php的末尾
它将从title标签中删除额外的"-“。
<script>
var str = document.title;
var res = str.split(" ");
var final_res="";
var count=0;
for(i=0;i<res.length;i++)
{
var n=final_res.indexOf("-");
if(n==-1)
{
count=0;
}
else
{
count=1;
}
if(res[i]!="-" || count==0)
{
final_res=final_res+" "+res[i];
}
else
{
final_res=final_res;
}
}
document.title=final_res;
</script>发布于 2014-03-25 19:12:13
我已经找到了解决方案:检查并删除WP中class- found tend.php中标题的"-“。
发布于 2014-03-25 19:14:50
首先,确保插件配置对于标题是正确的,如果问题不能在那里解决。
我们可以在functions.php或功能插件中使用以下过滤器修改SEO标题:
add_filter( 'wpseo_title', function( $title )
{
$new_title = str_replace( '- -', '-', $title ); // Adjust to your liking
return $new_title;
});https://stackoverflow.com/questions/22628692
复制相似问题