为wordpress日志关键词添加链接,增加内链和外链,有利于SEO,实现上述功能一般我们会通过安装插件来实现,比如:WP Keyword Link和SEO Smart Link等。
利用《批量替换WordPress文章中的文字》一文的方法,不用插件也可以实现自动为关键词添加内链和外链。
将下面代码粘贴到主题functions.php文件中:
function replace_text_wps($text){
$replace = array(
'HotNews' => '<a href="https://zmingcx.com/" rel="bookmark" title="HotNews Pro主题">HotNews</a>',
'知更鸟' => '<a href="https://zmingcx.com/" rel="bookmark" title="知更鸟博客">知更鸟</a>',
'关键词' => '<a href="https://zmingcx.com/" rel="bookmark" title="说明">关键词</a>'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter('the_content', 'replace_text_wps');本站文章大部分为原创,用于个人学习记录,可能对您有所帮助,仅供参考!

我的微信
微信号已复制
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!




