Code With Mark
Home
About
Resources
Contact

Nofollow Script

If you have been in this web world for a while, then you know how important it is to have a good website rank. The higher your rank is, the better chances you have in showing up on the first page of google search results.

There are several things you can do to keep your hard earned website ranking.

One of them being, adding “no follow” to all of your external links. But adding them manually could be a pain in the butt.

For Non-Wordpress Sites Adding No Follow

Just add the following code to your header and it will automatically add no follow and open all of the external links in a new window. Where it says “yoursitename”, type in your site name there.

<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script>
var $j = jQuery.noConflict();

$j(document).ready(function()
{

 $j("a[href^='http']:not([href*='yoursitename.com'])").attr("rel", "nofollow");
 $j("a[href^='http']:not([href*='yoursitename.com'])").attr("target", "_blank");

});

</script>

For WordPress Sites Adding No Follow

You can either use the following code as you like

<?php


//load up jQuery

wp_enqueue_script("jquery");

add_filter( 'wp_head', 'codewithmark_jQryNoFollow');

function codewithmark_jQryNoFollow()
{
 $site_url = codewithmark_get_base_url(get_site_url()); 
?>

<script>
var $j = jQuery.noConflict();
$j(document).ready(function()
{
 $j("a[href^='http']:not([href*='<? echo ($site_url) ?>'])").attr("rel", "follow");
 $j("a[href^='http']:not([href*='<? echo ($site_url) ?>'])").attr("target", "_blank");
});

</script>
<?php
}


function codewithmark_get_base_url($url) 
{ 
 //This function will take "http://google.com" and make it into "google.com
 $input = trim($url, '/');
 if (!preg_match('#^http(s)?://#', $input)) 
 {
 $input = 'http://' . $input;
 } 
 
 $urlParts = parse_url($input); 
 //$urlParts =$input ;
 // remove www
 $domain = preg_replace('/^www\./', '', $urlParts['host']); 
 return $domain;
} 
?>

Download (Nofollow WordPress Plugin)

 

Let me know what you think of this…

For Web Developers

Working Hard But Still Not Getting Ahead?

You finish a project, get paid, and then it's back to finding the next client.

Month after month, the cycle repeats.

That's why many web developers never build real financial freedom—even though they're highly skilled.

The developers creating long-term wealth are using those same skills to build SaaS products, plugins, and digital tools that generate recurring income.

What if your next project could pay you more than once?

Learn How To Build Monthly Income →
Easily Master MS AccessEasily Master MS AccessNext→

Related Posts

  • Form Validation in 1 Line
  • Easily Edit HTML Table Rows Or Cells With jQuery
  • Mastering Form Validation

Top Posts Viewed

Easily Edit HTML Table Rows Or Cells With jQuery
145 views
How To Create A Secure Login System With PHP And MySQL
134 views
PHP Simple Database Class
134 views

Categories

Courses
Excel
Google Script
Javascript
jQuery
Microsoft Access
MongoDB
Node JS
PHP
Quick Tip
Uncategorized
Wordpress