How to automatically set tags in WordPress and implement automatic internal links without plug-ins

888u

Last update at :2024-06-19,Edit by888u

Snail Blog has been using the WP keyword Link Plugin before, but found that this plug-in has not been updated for a long time, and it seems that it can no longer be found on the platform. So prepare to replace this plug-in. There are many similar WordPress plug-ins, such as Keywords to Links Converter, Auto Tag Links, etc., which can be implemented.

In line with the strategy of using less plug-ins and not using plug-ins if possible, we plan to implement them without plug-ins.

//Automatically convert TAG to internal link $match_num_from = 2; // How many times a TAG tag appears before adding a link $match_num_to = 1; // How many times do you add a link to the same tag 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;$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 = \ \”\\”.addcslashes($cleankeyword, \\'$\\’).\\”\\”;$limit = rand($match_num_from,$match_num_to);$content = preg_replace( \\'|(]+>)(.*)(\\'.$ex_word.\\')(.*)(]*>)| 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 the code to the current theme's Functions.php file. If there is a conflict and a problem occurs, we need to check whether it is incompatible. If we can't check it out, we can only use plug-ins to achieve it.

Recommended site searches: free proxy IP address, Shandong website registration, registration-free virtual space, Hong Kong server defense, free website space application, US host network, Chinese international domain name, Jiangsu high defense server, high defense server rental, registered domain name ,

How to automatically set tags in WordPress and implement automatic internal links without plug-ins

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码