Implementation of tag inner chain association effect of WordPress program without plug-in

Nowadays, whether it is a large website or a personal blog, what matters is not the weight of the website determined by the number of external links, but the content quality of the website itself and the construction of internal links, so that users / search engines can easily find the relevant content we need. The construction of internal link between contents is still quite important. Some of our users may like to make it by hand. Of course, this is very good. If we are afraid of trouble, we can use the tag Association set by WordPress as the internal link effect.

Generally, plugins can be used. we always prefers to use no plugin effect, so he sorted it into this no plugin to achieve tag inner link effect.

/ / number of connections < br >$match_ num_ From = 1; / / the number of less than one keyword is not replaced < br > 0$match_ num_ To = 2; / / a keyword can be replaced at most < br > by//Modules connected to WordPressadd_ filter(‘the_ content’,’tag_ link’,1);
//Sort by length < br > 1function tag_ sort($a, $b){
if ( $a->name == $b->name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
//Change tag keywords < br > tofunction 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 < br > 0$cleankeyword = stripslashes($keyword);
$url = “<a href=”$link” title=””.str_ replace(‘%s’,addcslashes($cleankeyword, ‘$’),__ (‘View all posts in %s’)).”””;
$url .= ‘ target=”_ blank” class=”tag_ link”‘;
$url .= “>”.addcslashes($cleankeyword, ‘$’).”</a>”;
$limit = rand($match_ num_ from,$match_ num_ to);
//Unconnected code < br > 0$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;
}

Put the above code script in the current wodpress topic FUNCTIONS.PHP In the file, the above description parameters are modified as needed. For example, this method is used in the content tag link of we’s blog.

Related Article
WordPress automatically intercepts part of the content of the article as a summary

In the daily release of articles, not every article may have an article summary, so the summary function of WordPress Read more

Is in WordPress Theme_ Home () and is_ front_ Different usage of page ()

Under normal circumstances, when we use WordPress to build a website, the home page is the default index.php Just call Read more

How to delete the version number tail of WordPress scripts and CSS style sheets

As an excellent website building program, WordPress is undoubtedly the largest user group in the world in terms of user Read more

Solve the problem of “upload error, please try again later” in WordPress image upload

One of the reasons why I like to use WordPress is that I have encountered problems. Basically, I can find Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image