WordPress怎麼設置內鏈?文章內容標籤自動加錨文本優化

由於WordPress文章自動錨文本插件Automatic Internal Links for SEO不支持標籤自動錨文本的功能。

如果能夠添加標籤關鍵詞錨文本,這樣不僅可以SEO優化我們的內部鏈接,還能讓用戶參考相關文章。

WordPress標籤如何自動添加內鏈?

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

歡迎加入陳溈亮博客的Telegram 頻道,獲取最新更新!

🔔 率先在頻道置頂目錄獲取寶貴的《ChatGPT 內容行銷AI 工具使用指南》! 🌟
📚 這份指南蘊含價值巨大,🌟難逢的機遇,切勿錯失良機! ⏰⌛💨
喜歡就分享和按贊!
您的分享和按贊,是我們持續的動力!

 

發表評論

您的電子郵箱地址不會被公開。 必填項已用 * 標註

滾動到頂部