How to remove the “nofollow” attribute from all internal links on a WordPress site

To remove the “nofollow” attribute from all internal links on your WordPress site, you can use one of the following methods:

Use a plugin:

There are several plugins available that can help you remove the “nofollow” attribute from your internal links. Some popular options include “Remove Nofollow,” “Nofollow Manager,” and “Nofollow Control.”

To install a plugin:

  1. Log in to your WordPress admin dashboard.
  2. Go to “Plugins” > “Add New.”
  3. Search for one of the plugins mentioned above.
  4. Install and activate the plugin.
  5. Configure the plugin settings according to your needs (each plugin may have slightly different settings).

Edit your theme’s functions.php file:

If you prefer not to use a plugin, you can manually remove the “nofollow” attribute from your internal links by editing your theme’s functions.php file. Follow these steps:

  1. Log in to your WordPress admin dashboard.
  2. Go to “Appearance” > “Theme Editor.”
  3. In the right sidebar, locate and click on the “functions.php” file.
  4. Add the following code snippet at the end of the file:
function remove_nofollow_from_internal_links($content) {
$site_url = get_site_url();
$pattern = "/<a(.*?)href=[\"']" . preg_quote($site_url, "/") . "(.*?)[\"'](.*?)rel=[\"']nofollow[\"'](.*?)>/i";
$content = preg_replace($pattern, '<a$1href="' . $site_url . '$2"$3$4>', $content);
return $content;
}
add_filter('the_content', 'remove_nofollow_from_internal_links');

or this code:

function remove_nofollow($string) {
$internal = get_site_url();
if ( str_contains( $internal, $string ) {
$string = str_ireplace(' rel="nofollow"', '', $string);
}
return $string;
}
add_filter('the_content', 'remove_nofollow');
  1. Click “Update File” to save the changes.

This code snippet will remove the “nofollow” attribute from all internal links in your site’s content. However, please be aware that editing your theme’s functions.php file can have unintended consequences if not done correctly. It’s always a good idea to create a backup of your site before making changes to the code.

If you’re using a page builder or any other custom plugin to create content, you may need to use a different method or consult the plugin documentation to remove the “nofollow” attribute from internal links.

Leave a Reply

Your email address will not be published. Required fields are marked *