how to automatically add tag links to the article

Today, I’d like to share a WordPress SEO optimization tip, which can realize the automatic addition of keyword tags in the article.

Inside the link of good outside, naturally needless to say, it can let Baidu spider in your website crawling more places.

Of course, many WordPress plugins can also achieve this function, but today wpto tutorial network to share with you is not plugin to the article keyword tag automatically add the link method.

Then how to make the keyword tags of WordPress sites automatically add internal links? In fact, we only need to add the functions.php File to add a piece of code can be achieved.

//WordPress Article keywords automatic internal link

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){
	$match_num_from = 1;	
	$match_num_to = 1;	
	$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;

Related Article
WordPress details optimization to automatically add ALT and title information to the article image

Friends who know a little bit about SEO optimization should understand that image ALT and image title optimization are very Read more

WordPress displays the registration time of the login user in the frontend

When using WordPress to build a website, some users want to display the user registration time in the frontend, but Read more

WordPress adds the number of SQL queries at the bottom

An excellent woodpress theme is definitely that the less SQL consulting is used, the better. How can we see how Read more

Some WordPress articles can be seen after comments / replies

If we want to hide part of the content of the article and need the user's comments and replies to 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