Wordpress has no plug-in to automatically add links to the document content tags

Source: Internet
Author: User
Insert the following code into the functions. php file. remember to insert it to & lt ;? Php and? & Gt; otherwise, an error occurs: // number of connections $ match_num_from1; // do not replace $ match_num_to10 if there is less than one keyword; // a keyword can be replaced at most // module a connected to WordPress

Insert the following code into the functions. php file. remember to insert it Otherwise, an error occurs:

// Number of connections $ match_num_from = 1; // do not replace $ match_num_to = 10 if there is less than one keyword; // a keyword can be replaced at most // add_filter ('The _ content', 'tag _ link', 1) of the WordPress module; // function tag_sort ($, $ B) {if ($ a-> name = $ B-> name) return 0; return (strlen ($ a-> name)> strlen ($ B-> name ))? -1: 1;} // change the tag keyword 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; // connection code $ cleankeyword = stripslashes ($ keyword); $ url = "". addcslashes ($ cleankeyword, '$ '). ""; $ limit = rand ($ match_num_from, $ match_num_to); // code without connection $ 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 ;}

This code is extracted directly from the plug-in, and there may be additional code. Currently, there is no bug in the test. In addition, after testing, it is recommended that you set $ match_num_to to 1 in the code, this is the best experience. Otherwise, the tags and links on the full screen will be dazzled. after the change to 1, it will be refreshing and simple and clean. this is my pursuit ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.