divPress

Discover WordPress. Get acquainted from level-one about the nuances of developing for Wordpress. Learn to code like a Pro using advanced WordPress coding.

Do subscribe to get regular updates via RSS.

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

Remove the menacing “title” attribute from all elements under the wp_list_categories() function.

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.

Was this post useful? Share on Twitter or Facebook and spread the love.   

Related Posts

Now What?

Leave a Reply

Allowed Tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>