Remove “View all posts filed under” from wp_list_categories Title attribute

WordPress automatically includes the Title attribute for each element in the wp_list_categories() function. It looks pretty bad when it you’re implementing the category list in a place like the top navigation menu.

1
wp_list_categories();

Here is a way to take off the “Title” attribute from wp_list_categories(). wp_list_categories has a parameter echo [like many other wp functions], which when set to 0 does not echo the code onto the screen. This way, we can get the whole string onto a php variable.

To change Title attribute to “Category Name” instead of “View all posts filed under Category Name” :

1
2
3
$categoriesVar = wp_list_categories("echo=0");
$categoriesVar = str_replace( "View all posts filed under " , ' ' , $categoriesVar );
echo $categoriesVar;

To completely remove the title attribute:

1
2
3
$categoriesVar = wp_list_categories("echo=0");
$categoriesVar = preg_replace( '/title=\"(.*?)\"/' , ' ' , $categoriesVar );
echo $categoriesVar;

The same code can also be written in a single statement:

1
2
echo preg_replace('/title=\"(.*?)\"/','',wp_list_categories("echo=0&title_li="));
/* Strips off Title attribute from wp_list_categories */

Update: Feb 08, 2010

WordPress checks for the category description before it defaults the title to “View all posts filed under “. So, you could just add a single whitespace as the description of categories to not show anything in the title.
- Thanks to Justice Chad for this.

Posted by

Deepak Thomas is a guy who hearts wordpress. If you're having trouble with wordpress, tweet it with @thinkdj and he'll try to solve your queries for a box of chocolates.

2 comments » Write a comment

  1. Thanks a lot. it was looking pretty bad on my theme (it has a dropdown menu and when hovered, the browser's default title attribute handler shows the title)

Leave a Reply to Raul Cancel reply

Required fields are marked *.


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>