日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

免插件为WordPress文章中标签添加内链

發(fā)布時間:2025/3/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 免插件为WordPress文章中标签添加内链 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

給文章標(biāo)簽添加內(nèi)鏈,意思就是說,如果你文章中出現(xiàn)了和標(biāo)簽一樣的文字,那么這個文字就會自動成為標(biāo)簽鏈接,你點(diǎn)擊這個鏈接就會查看到所有含有該標(biāo)簽的文章,這個能方便用戶瀏覽,據(jù)說還利于SEO。下面說說方法:
把下面的代碼添加到function.php中就可以了

展開/收縮
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 //自動為文章標(biāo)簽添加該標(biāo)簽的鏈接 $match_num_from = 1;? // 一個標(biāo)簽在文章中出現(xiàn)少于多少次不添加鏈接 $match_num_to = 1; // 一篇文章中同一個標(biāo)簽添加幾次鏈接 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; } //為符合條件的標(biāo)簽添加鏈接 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 = "<a href=\"$link\" title=\"".str_replace('%s',addcslashes($cleankeyword, '$'),__('View all posts in %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; }

看看效果圖:

總結(jié)

以上是生活随笔為你收集整理的免插件为WordPress文章中标签添加内链的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。