Mar
11
2009

Remove the Title Attribute from WordPress Category and Page Lists

by   |  Posted in Tutorials  |  50 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').

About the author:

A freelance web developer living in Montreal who spends most of his time writing for this site and building Premium themes for WordPress. You can find him on Twitter @bavotasan.

Site5 Affiliate Link
Share the love...

Tags: , , , , , , , ,

Short URL: http://bit.ly/a3jbmJ

Discussion 50 Comments

  1. Ash Blue on October 23, 2010 at 12:58 am

    Great snippet, I’ve now used it on several projects because I keep on forgetting the parameters for preg replace >_<

  2. Sam on November 13, 2010 at 2:00 pm

    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 ~:

    • c.bavota on November 14, 2010 at 2:36 pm

      It should work for all the instances you asked about.

  3. staupenet on January 22, 2011 at 3:56 pm

    Thanks so much!! Exactly what I needed. Works perfectly!

  4. Franner on January 25, 2011 at 6:34 pm

    Thanks!

    This was just what i needed :-)

  5. Ralph on February 27, 2011 at 5:02 am

    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

  6. zzz on March 14, 2011 at 2:30 am

    where do i add the above mentioned function ????

    • c.bavota on March 14, 2011 at 10:01 am

      Add the function code block to functions.php in your theme directory. They you can use wp_list_pages('echo=0') anywhere you want.

  7. marion on March 22, 2011 at 11:57 am

    Thank you, this works for custom taxonomies as well…

  8. Gary Jones on March 28, 2011 at 5:15 pm

    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.

  9. WordPress Developer on April 6, 2011 at 1:39 am

    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!