自动为WordPress关键词添加链接(非插件)

为wordpress日志关键词添加链接,增加内链和外链,有利于SEO,实现上述功能一般我们会通过安装插件来实现,比如:WP Keyword Link和SEO Smart Link等。

当然不用插件也可以实现自动为关键词添加内链和外链。

将下面代码粘贴到主题functions.php文件中:

function replace_text_wps($text){ 
 $replace = array( 
 'wordpress' => '<a href="https://pdbn.top/category/nxdm/wp-notes/" rel="bookmark" title="wordpress笔记">wordpress</a>', 
 'css' => '<a href="https://pdbn.top/category/nxdm/divcss-notes/" rel="bookmark" title="css">css</a>', 
 '爱博说' => '<a href="https://pdbn.top/" rel="bookmark" title="爱博说">爱博说</a>' 
 ); 
 $text = str_replace(array_keys($replace), $replace, $text); 
 return $text; 
} 
 
add_filter('the_content', 'replace_text_wps');

原文来自http://zmingcx.com/automatically-add-links-keyword.html