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

为wordpress日志 关键词添加链接,增加内链和外链,有利于SEO,实现上述功能一般我们会通过安装插件来实现,比如:WP Keyword Link和SEO Smart Link等。网上很多代码都是失效,用了一下知更鸟的代码特意分享转载学习。

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

//Auto Link Tags
function replace_text_wps($text){  
    $replace = array(  
        'bootstrap' => '<a href="https://www.511yj.com/" rel="bookmark" title="bootstrap">v</a>',  
        '511' => '<a href="https://www.511yj.com/" rel="bookmark" title="511遇见">511</a>',  
        'wordpress' => '<a href="https://www.511yj.com/" rel="bookmark" title="wordpress">wordpress</a>'  
    );  
    $text = str_replace(array_keys($replace), $replace, $text);  
    return $text;  
}  
 
add_filter('the_content', 'replace_text_wps');

修改以上的关键词和链接地址就可以了。


发布日期:

所属分类: WordPress、WordPress 插件 标签: