Home arrow PHP arrow 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.

  1. Standards-compliant Link Targets with Wordpress
  2. Dynamically adding rel=’no follow’
  3. JavaScript link targets
  4. Putting it all together
By: Nilpo
Rating: starstarstarstarstar / 4
December 19, 2007

print this article



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.

Once the page loads, a JavaScript scans for all outbound links and dynamically targets them to a new window.  This results in outbound links that open in new windows, while keeping the site both SEO friendly and standards compliant.

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.

>>> More PHP Articles          >>> More By Nilpo

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: