WordPress文章關鍵詞自動添加鏈接前端開發
導讀:前端開發前端開發 文章頁面的關鍵詞自動添加內鏈,有利于SEO,方便讀者查看所有相關關鍵詞的所有文章。建議最多替換2個重復的詞!避免過度SEO。在主題的functions.php建設網站公司網站建設多少錢。
文章頁面的關鍵詞自動添加內鏈,有利于SEO,方便讀者查看所有相關關鍵詞的所有文章。 建議最多替換2個重復的詞!避免過度SEO。 在主題的functions.php文件中添加以下代碼:
/* *自動為文章內的標簽添加內鏈開始 */ //連接數量 $match_num_from = 1; //一個關鍵字少于多少不替換 $match_num_to = 1; //一個關鍵字最多替換次數 //連接到WordPress的模塊 add_filter('the_content','tag_link',1); //按長度排序 function tag_sort($a, $b){ if ( $a->name == $b->name ) return 0; return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1; } //改變標簽關鍵字 function tag_link($content){ global $match_num_from,$match_num_to; $postt網站seo優化課程ags = get_the_tags(); if ($posttags) { u企業網站建設sort($posttags, "tag_sort"); foreach($posttags as $tag) { $link = get_tag_link($tag->term_id); $keyword = $tag->name; //連接代碼 $cleankeyword = stripslashes($keyword); $url = "<a href=\"$link\" title=\"".str_replace('%s',addcslashes($cleankeyword, '$'),__('查看所有文章關于 %s'))."\""; $url .= 'target="_blank"'; $url .= ">".addcslashes($cleankeyword, '$')."</a>"; $limit = rand($match_num_from,$match_num_to); //不連接的代碼 $content = preg_replace( '|(<a[^>]+>)(.*)('.$ex_word.')(.*)(</a[^>]*>)|U'.$case, '$1$2%&&&&&%$4$5',建設網站公司 $content); $content = preg_replace( '|(<img)(.*?)('.$ex_word.')(.*?)(>)|U'.$case, '$1$2%&&&&&%$4$5', $content); $cleankeyword = preg_quote($cleankeyword,'\''); $regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case; $content = preg_replace($regEx,$url,$content,$limit); $content = str_replace( '%&&&&&%', stripslashes($ex_word), $content); } } return $content; }相關建設網站公司網站建設多少錢。聲明: 本文由我的SEOUC技術文章主頁發布于:2023-05-28 ,文章WordPress文章關鍵詞自動添加鏈接前端開發主要講述wordpress,超鏈接網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_11644.html