The solution you are going to see is in the form of a Wordpress plugin. If you are not using a Wordpress site, this can certainly be modified to work for you too. This could easily be a Joomla mambot, for example. The key is to make sure that this code is executed before your page is displayed to the end-user. It’s also important to understand that this needs to be accomplished server-side. You could easily write a JavaScript to perform this task when a page loads; however, that would be ineffective for two reasons: primarily because search engine robots don’t use JavaScript, and because JavaScript is executed after the page load completes. While I’ve chosen PHP because Wordpress is written in PHP, you could easily use ASP or any other server-side solution to accomplish this task. When I decided to make this plugin for Wordpress, I knew of a similar solution (Wikipedia nofollow by Ken Yasumoto-Nicolson) that added rel=”nofollow” to Wikipedia links. Since it is released under the GNU GPL, I decided to save some time and just edit this code to work for me. The code actually works pretty easily. When a page is created, it checks for any links. It then processes each link, in turn, to see if it is internal or external and then adds the rel=”nofollow” attribute as needed. It even checks to make sure that the attribute doesn’t exist already. To use this plugin, just drop the external_links.php file into your plugin folder and activate it. You’re all set. However, if you’re like me, you have multiple sites. I don’t want to exclude my own sites. But since the domain is different, they also get the rel attribute. Here’s how you can change it so that doesn’t happen. Open external_links.php in any text editor and find the section below in the parse_nofollow() function. if ( wp_get_domain_name_from_uri($matches[3]) != $local_domain && wp_has_no_rel_nofollow( $matches[1] ) && wp_has_no_rel_nofollow( $matches[4] ) ) { This is the section of code that determines what links will have the rel attribute added to them. It requires that they do not link to the local domain and that they do not already have a rel=”nofollow” attribute. We can add more domains to exclude by adding a line like the following: wp_get_domain_name_from_uri($matches[3]) != "myotherdomain.com" && This line simply excludes anything that links to the domain provided. You can add as many as needed for all the domains that you own. Your final code should look something like this: if ( wp_get_domain_name_from_uri($matches[3]) != $local_domain && wp_get_domain_name_from_uri($matches[3]) != "myotherdomain.com" && wp_get_domain_name_from_uri($matches[3]) != "anotherdomain.com" && wp_has_no_rel_nofollow( $matches[1] ) && wp_has_no_rel_nofollow( $matches[4] ) ) { Now every external link on your site will have rel=nofollow dynamically added to the "a" tag.
blog comments powered by Disqus |
|
|
|
|
|
|
|