Title Attributes for WordPress Post Navigation
Improve accessibility by adding title attributes to your WordPress userspace.
This article applies specifically to WordPress 2.0.2, but may be generalized to any WP 2.0+ version.
By default, WordPress navigation links omit the title attributes for both page and post views. Title attributes for links provide additional information that can improve the accessibility of your website. This is especially true when images or text symbols exclusively are used for navigation.
To add title attributes to WordPress page-view links (e.g., links for index, archive, and category views), open the file wp-includes/template-functions-links.php and find the functions previous_posts_link (line #494) and next_posts_link (line #459).
Within each function, replace the following line:
echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
..with this:
echo '" title="EDIT THIS">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
Next, replace the EDIT THIS text in each function with “Previous Posts” and “Next Posts”. Keep in mind the reverse chronological order by which these links navigate. Remember to check a few page views and then you are done.
Now, to add the title attribute to navigation links within individual post views. Open the same file as above, wp-includes/template-functions-links.php and find the functions previous_post (line #336) and next_post (line #357).
Within each function, replace the following line:
$string = '<a href="'.get_permalink($post->ID).'">'.$next;
..with this:
$string = '<a href="'.get_permalink($post->ID).'" title="EDIT THIS">'.$next;
Next, replace the EDIT THIS text in each function with “Previous Post” and “Next Post” respectively. Remember to check a few post views and then you are done.
Related articles
- Reversing WordPress Page Navigation Order
- Passing Quotation Marks via wp_link_pages
- WordPress Notes Plus
- WordPress RDF Source Makeover
- Permalink Enlightenment
- WordPress Core File Edits at Perishable Press
- WordPress Core Hacks Used at Perishable Press
About this article
This is article #107, posted by Perishable on Sunday, April 23, 2006 @ 05:43pm. Categorized as Accessibility, WordPress, and tagged with attribute, code, navigation, title, tweaks, upgrade, WordPress. Updated on November 04, 2007. Visited 15032 times. 1 Response »
1 • January 7, 2007 at 12:11 pm — Collin1000 says:
Hay, nice site. Ive been lurking on your blog for quite some time and just wanted to say you do a really great job. I love your blog and just wanted to take the time to comment and tell you how much I love your blog.