How to remove the noopener noreferrer attribute automatically added to links in WordPress

888u

Last update at :2024-06-11,Edit by888u

Today, an IDC business owner accidentally talked to Snail about why Snail 789 blog’s access links could not be accurately counted. In fact, several people had told Snail about this, so Snail looked for the reason. In fact, the problem is that all external links have the "noopener noreferrer" attribute added. "noopener noreferrer" means the link "do not open" and "do not track". In fact, these two are automatically added to the link by WordPress for security reasons. In addition, if you want the statistics site to be able to track the number of visits normally, you must cancel the two attributes "noopener noreferrer". In this article, Snail will share with you how to remove the noopener noreferrer attribute automatically added by WordPress links, the solution for WordPress links to automatically add Noopener Noreferrer, and how to use database SQL statements to batch delete the "noopener noreferrer" that has been generated in WordPress articles with one click. .

1. Prohibit automatic addition

The "noopener noreferrer" attribute is added by WordPress to links by default. We only need to add the following code at the end of the theme "functions.php" file. Newly published articles will not automatically add "noopener noreferrer" to the link. "Attribute."

//WordPress removes the rel=\"noopener\" attribute in the link add_filter(\'tiny_mce_before_init\',\'tinymce_allow_unsafe_link_target\'); function tinymce_allow_unsafe_link_target( $mceInit ) {$mceInit[\'allow_unsafe_link_target\']=true; return $mceInit;}

2. Batch deletion of SQL statements

Regarding using SQL statements to replace WordPress article content in batches, Snail has previously introduced it in WordPress Tips: How to batch replace WordPress site URL link addresses by using SQL commands. In fact, the principle is the same this time. What we need to modify in batches is the "wp_posts" table. Just use the code below to replace it in batches.

UPDATE wp_posts SET post_content = REPLACE( post_content, \'noopener noreferrer\', \'\' )

Recommended site searches: How to rent a server, rent a server with US high-defense, same IP site query, free website space application, independent IP virtual host, cn domain name price, domain name registration price, domain name query, ICP fast filing, PHP space application ,

How to remove the noopener noreferrer attribute automatically added to links in WordPress

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码