實(shí)現(xiàn)起來(lái)也很簡(jiǎn)單,只需在主題文件夾中的function.php加入一段代碼即可實(shí)現(xiàn)tag自動(dòng)內(nèi)鏈。
WordPress文章關(guān)鍵詞自動(dòng)內(nèi)鏈到相關(guān)標(biāo)簽頁(yè),提高網(wǎng)站SEO,增加用戶粘性
函數(shù)代碼如下:
- //WordPress文字標(biāo)簽關(guān)鍵詞自動(dòng)內(nèi)鏈
- $match_num_from = 1; //一篇文章中同一個(gè)關(guān)鍵字少于多少不錨文本(這個(gè)直接填1就好了)
- $match_num_to = 2; //一篇文章中同一個(gè)關(guān)鍵字最多出現(xiàn)多少次錨文本(建議不超過(guò)2次)
- 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;
- $posttags = get_the_tags();
- if ($posttags) {
- usort($posttags, "tag_sort");
- foreach($posttags as $tag) {
- $link = get_tag_link($tag->term_id);
- $keyword = $tag->name;
- $cleankeyword = stripslashes($keyword);
- $url = "";
- $limit = rand($match_num_from,$match_num_to);
- $content = preg_replace( '|(]+>)(.*)('.$ex_word.')(.*)<\/pre>(]*>)|U'.$case, '$1$2%&&&&&%$4$5', $content);
- $content = preg_replace( '|()|U'.$case, '$1$2%&&&&&%$4$5', $content);
- $cleankeyword = preg_quote($cleankeyword,'\'');
- $regEx = '\'(?!((<.*?)|(]*?)>)|([^>]*?))\'s' . $case;
- $content = preg_replace($regEx,$url,$content,$limit);
- $content = str_replace( '%&&&&&%', stripslashes($ex_word), $content);
- }
- }
- return $content;
- }
- add_filter('the_content','tag_link',1);
將以上代碼添加到functions.php文件倒數(shù)第二行,再查看文章,你會(huì)發(fā)現(xiàn)文章中出現(xiàn)的tag標(biāo)簽文字自動(dòng)內(nèi)鏈了,通過(guò)改變代碼中的數(shù)字調(diào)節(jié)內(nèi)鏈個(gè)數(shù)。文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.ykday.cn/7813.html 文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.ykday.cn/7813.html
版權(quán)聲明:文章圖片資源來(lái)源于網(wǎng)絡(luò),如有侵權(quán),請(qǐng)留言刪除!!!
評(píng)論