Remove the Title Attribute from WordPress Category and Page Lists
by Bandicoot Marketing on | Posted in Tutorials | 53 comments
I was creating a drop down menu for the categories in my Magazine Basic theme and I came across something that started to annoy me a bit. When you hover over the menu item, and the sub-menu dropped down, a title attribute would appear and cover some of the menu. This title attribute it hard wired into WordPress. Just hover over any menu item above and you will see a yellow box appear that says something like “View all posts files under…”.
This is a useful attribute to add to any site in regards to the Web Accessibility Initiative, but if it interferes with the basic navigation of your site, I think it is okay to nix it.
Here is a simple pieces of code that you can use to remove the title attribute from your category list:
<?php $categories = wp_list_categories('echo=0'); $categories = preg_replace('/title=\"(.*?)\"/','',$categories); echo $categories; ?>
If you really want to get fancy, you can add this as a function to your theme’s function.php file. If the file doesn’t exist, just create it.
Add this:
<?php function categories_without_title_attribute() { $categories = wp_list_categories('echo=0'); $categories = preg_replace('/title=\"(.*?)\"/','',$categories); echo $categories; } ?>
Now when you want to call your category list, use instead of
.
You can do the same to your page lists, just replace wp_list_categories('echo=0')
with wp_list_pages('echo=0')
.
53 comments for “Remove the Title Attribute from WordPress Category and Page Lists”