How does WordPress add nofollow attribute to the external link in the article

What is nofollow?

Nofollow is the attribute value of the a tag.

What is the role of nofollow?

The use of nofollow is to tell search engines not to track links on this page or this specific link, that is, they will not export weights to this link.

Nofollow is important for WordPress optimization. If there is an outside link address in the article, it is necessary to add nofollow to the link address.

Nofollow case

<a href="https://wpfans.org/" rel="nofollow" >Theme King</a>

usage method

Add the following code to the topic functions.php Documents

//Add to the article external link nofollow attribute 
add_filter('the_content','web589_the_content_nofollow',999);
function web589_the_content_nofollow($content){
	preg_match_all('/href="(.*?)" rel="external nofollow" /',$content,$matches);
	if($matches){
		foreach($matches[1] as $val){
			if( strpos($val,home_url())===false ) $content=str_replace("href="$val"", "href="$val" rel="nofollow" ",$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

Add article browsing history function to WordPress

This article was last updated on January 22, 2014. It has not been updated for more than three years. If Read more

WordPress tips: get statistics of the number of pictures in the article

As far as I know, WordPress has no function to count the number of pictures in the article, so to Read more

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 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