由於WordPress文章自動錨文本插件Automatic Internal Links for SEO不支持標籤自動錨文本的功能。
如果能夠添加標籤關鍵詞錨文本,這樣不僅可以SEO優化我們的內部鏈接,還能讓用戶參考相關文章。
WordPress標籤如何自動添加內鏈?

那麼如何讓WordPress網站上的文章,自動添加標籤內鏈呢?
其實我們只需要在主題目錄下的functions.php文件中,添加一段php代碼就可以實現。
WordPress文章內容標籤自動添加錨文本內鏈
/**
* WordPress文章内容标签自动加锚文本内链
* https://www.chenweiliang.com/cwl-27651.html
**/
function wptag_auto_add_anchor_text_link($content){
$limit = 1; // 设置WordPress文章同一个标签,自动添加几次内链?
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = '<a target="_blank" href="'.$link.'" title="'.str_replace('%s', addcslashes($cleankeyword, '$'), __('View all posts in %s')).'">'.addcslashes($cleankeyword, '$').'</a>';
$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s';
$content = preg_replace($regEx,$url,$content,$limit);
}
}
return $content;
}
add_filter( 'the_content', 'wptag_auto_add_anchor_text_link', 1 );添加代碼到WordPress主題的functions.php文件後,再看我們的文章。
當我們添加的標籤關鍵詞出現時,是否有自動添加內部鏈接?
希望陳溈亮博客( https://www.chenweiliang.com/ ) 分享的《WordPress怎麼設置內鏈?文章內容標籤自動加錨文本優化》,對您有幫助。
歡迎分享本文鏈接:https://www.chenweiliang.com/cwl-27651.html