WordPress adds nofollow to the outside link address of the article

What is nofollow?

Nofollow is the attribute value of a tag in the HTML page. It’s used to tell search engines “don’t track links on this page” or “don’t track specific links,” that is, it won’t export weights to this link.

It is important for wordless SEO optimization. So it is necessary to add nofolw to the link address if there is an external link address in the article

Add case

Add rel = “nofollow” and do not export your own website weight

<a href="https://www.wpjc.net/" rel="nofollow" >WPTooTutorial network</a>

usage method

Add the following code to the topic functions.php Documents

//Add to the article linknofollow
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
How to add user defined upload avatar function in WordPress

Friends who use WordPress to build a website should know that WordPress itself does not have the function of uploading Read more

How to get the number of articles and comments of the current logined user in WordPress

When developing WordPress Theme user center, I want to get the number of articles and comments of current logged in 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

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

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