Last update at :2024-01-27,Edit by888u
We know that when building a website, we will try to increase internal links or link external websites to our own web pages to increase the probability of spider crawling and prevent the loss of website weight. Of course, as an evaluation station, we often share various IDC hosts. Business promotions and product purchase links. At this time, on the one hand, we do not want our articles to be plagiarized by other evaluation sites, let alone linking to too many external links.
Fortunately, we have some methods to convert the external link of the article body into an internal link, such as plug-ins. However, in this article, our blog will share a tutorial on how to automatically convert the external link of the article body to an internal link in WordPress without a plug-in, in case the website Loss of weight prevents articles from being plagiarized.
Take our blog DUX theme as an example:
1. Automatically add the nofollow attribute to the external link of the article. Add the following code to the function-theme.php file under the DUX theme folder:
/* *Automatically add nofollow attribute to external links of articles */ add_filter('the_content','web589_the_content_nofollow',999); function web589_the_content_nofollow($content){ preg_match_all('/href="(http.*?)"/',$content,$matches); if($matches){ foreach($matches[1] as $val){ if( strpos($val,home_url())===false ) $content=str_replace("href=\"$val\"", "rel=\"nofollow\" href=\"" . get_bloginfo('wpurl'). "/go?url=" .base64_encode($val) . "\"",$content); } } return $content; }2. Jump to the go internal link, create a folder named "go" in the root directory of the website, create the index.php file under the go folder, and write the following code in the file:
Just replace the URL link in $b = "https://www.laoliublog.cn/" with your own.
3. The above code adds a jump beautification effect. The source link has been encrypted with base64 in the code, and nofollow has been added. However, spiders may still be able to crawl. All spiders are prohibited from crawling in the /go?url directory in Robots!
Disallow: /go/ Disallow: /go?urlThrough the above steps, you can realize that the external link of the WordPress blog article body without plug-in code can be automatically converted to the internal link~
Recommended site searches: Mainland China registration-free space, hosting space, foreign hosting, free all-purpose space application, mainland China space, Hong Kong cloud hosting, renting server mainland China agent IP, cn domain name registration, domain name registration service website,
p>
发表评论