Remove the Title Attribute from WordPress Category and Page Lists
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').




Great snippet, I’ve now used it on several projects because I keep on forgetting the parameters for preg replace >_<
does it work for images tooltip title or whatever they called too ?
so this one should be in the function.php ?
and this one where?
You can do the same to your page lists, just replace wp_list_categories(‘echo=0′) with wp_list_pages(‘echo=0′).
really sorry for asking such a question ~:
It should work for all the instances you asked about.
Thanks so much!! Exactly what I needed. Works perfectly!
Thanks!
This was just what i needed
Where exactly do I change or add this?
The last thing I tried was this:
http://www.theme-junkie.com/support/index.php/topic,2967.0.html
But this didn’t work as you can see on my site : http://www.myrun.com.au
Would love to hear your opinion.
Ralph
where do i add the above mentioned function ????
Add the function code block to functions.php in your theme directory. They you can use
wp_list_pages('echo=0')anywhere you want.Thank you, this works for custom taxonomies as well…
I created a three level drop-down menu for the site, which worked great until WordPress decided to show little titles boxes near the menu items. I tried running the plug-in shown above but got a fatal error. I am using Revolution (now StudioPress) City Portal theme. Hopefully there is an easy way to stop these totally redundant boxes from showing up.
This is a slick piece of code and very useful for custom WordPress themes. preg_replace and regular expressions in general are pretty tough to implement, so hats off to you for making this code available. Thanks!