HomePHP Standards-compliant Link Targets with Wordpress
Standards-compliant Link Targets with Wordpress
Wordpress is an extremely popular site blogging software written in PHP. It does a great job of creating standards-compliant web sites. Plus it’s a good idea to continue with that effort when adding modifications.
I ran into an issue on one of my own Wordpress sites the other day, so I decided to share with you my solution. What happened was I added an SEO modification to my site that finds all external links in my page and adds a rel=”nofollow” attribute to them. However, I also like to target my external links to new windows, but the target attribute for the “a” tag has been depreciated and will not validate under XHTML strict.
So I decided to combine a solution for both. I wanted to create a PHP script that finds all links and checks the URL to see whether the destination is inbound or outbound. If it is outbound, it adds a rel=”nofollow” attribute to the link.
For those who don’t understand the need for using the rel attribute on outbound links, this is a technique used by web masters to help preserve PageRank and increase search engine ranking. I’ll try to explain this very briefly.
Search engines rank pages based on a number of different criteria. Two of these are inbound and outbound links. As a web master, you can only control the second. These outbound links are followed by the search engine spider, which determines how well they relate to your site. The more closely related they are, the better your site will rank because the search engines have determined that this is more useful to end users.
But imagine for a second that you are hosting a site about cooking and a user in your forums posts a link to a site about cars. Now what? A search engine robot is going to determine that this site is unrelated and may penalize your ranking! Adding the rel attribute will instruct the robot not to, preventing any loss to your site.
Now, this is certainly less of a concern if you do not have any publicly created content, but you’re certainly not out of the woods yet. Perhaps you have an about page that links to your favorite band. Or maybe you have a page that links to all of your clients. All of these scenarios result in outbound links to sites that do not directly relate to your site’s main content.