Ads

Hi Friends Please Visit My BLOG for more....



Thursday, April 21, 2011

The secrets of using external links in WordPress

When you create a blog post that points to some external websites, search engines consider the external links when rebuilding their indexes. Although such links are good for those sites as they improve their positions in search results, they may be bad for your blog if a search engine reckons it among link catalogs with all the ensuing consequences.

Well, this problem has a very elegant solution. Everybody knows that you should set the property rel="external nofollow" for an external link.



<a href="http://google.com/" rel="external nofollow">Google</a>


By doing this, you tell search engines explicitly that the link is external, and so they should disregard it at indexing.

You can apply the solution to WordPress as follows:

Edit the functions.php file, which you can find in the topic's directory, or create it if it doesn't exist yet.

Here's how a WordPress-specific link for editing the file looks:

/wp-admin/theme-editor.php?file=/themes/your_theme/functions.php&theme=&dir=theme

You need to put the following function and "stener" in the end of the file, just before ?>


function set_link_rel($content)
{
        $content = preg_replace('|<a (.*) rel="(.+)"(.*)>(.*)</a>|imsU', "<a \${1}\${3}>\${4}</a>", $content);
        $content = preg_replace('#<a (.*) href="(https?://)(.+)"(.*)>(.*)</a>#imsU',
                "<a \${1} href=\"\${2}\${3}\" rel=\"external nofollow\"\${4}>\${5}</a>", $content);
        return $content;
}
add_filter('the_content', 'set_link_rel');


After that, each time a post is added, WordPress will replace all external links with links having the property rel="external nofollow" set.

Now you needn't worry about putting lots of external links in your posts. Because no matter how many links you use, your blog won't be penalized by search engines.

No comments:

Post a Comment