WordPress Tips - Removing The Title Attribute From wp_list_categories & wp_list_pages
I noticed in the WordPress forums that a lot of people were asking how to remove the title="example" attribute from the links generated by the WordPress template tags wp_list_categories and wp_list_pages. The title attribute is what generates the little text box with something like "View all posts filed under <category>" when you hover over a link.
I had previously devised a 'hack' for removing the dreaded title attribute for a theme I worked on. The key is to set the 'echo' parameter of the function to '0' and then to use preg_replace code to remove the title attribute. Here is the code:
wp_list_categories:
<?php $cool_cats = wp_list_categories('echo=0'); $cool_cats = preg_replace('/title=\"(.*?)\"/','',$cool_cats); echo $cool_cats; ?>
wp_list_pages:
<?php $clean_page_list = wp_list_pages('echo=0'); $clean_page_list = preg_replace('/title=\"(.*?)\"/','',$clean_page_list); echo $clean_page_list; ?>
Personally I don't mind having the titles on my site navigation, and I use the NAVT plugin to generate my nav, so the template tags don't apply for me.










WordPress Tips - Removing The Title Attribute From wp_list_categories & wp_list_pages | Sam Burdge…
I noticed in the WordPress forums that a lot of people were asking how to remove the title=”example” attribute from the links generated by the WordPress template tags wp_list_categories and wp_list_pages. The title attribute is what generates the lit…
Where would I place the code snippet for wp_list_pages?
Hi Tom
The code snippet above is meant to replace the existing wp_list_pages function used in your theme.
wp_list_pages is usually called in either header.php, footer.php or sidebar.php of your theme.
More info about wp_list_pages here:
http://codex.wordpress.org/Template_Tags/wp_list_pages
Sam
Thanks for the code snippit! I had started using nicetitles for http://chattanoogaswing.org and then noticed that wp_list_pages added tiles to all the links!
The calendar I was using doesn’t add a class for the dates I wanted the tooltips on. If it did, I could just modify the nicetitles javascript to only select that class of element.
Using your little regex to remove the titles form wp_list_pages is much easier!
Also, cool theme you’ve got going on here. I like the green-on-black console look.
thanx a lot for this tip !.
I have another question for everybody : How can I remove a hyperlink from wp_list_pages, but only from the first ul in the heirachy ?
thx for all who will consider my question !
Sébastien from France
Yet another thank you from me. Have been looking for a plugin to do this, but this is even better. Do you think it’s better for me to write a private plugin implementing this small little code? to avoid the snippet to be removed when I upgrade WP.
W9xinK great tips. I enjoyed reading this,
Exactly what I was looking for, thanks a lot!
Thanks a lot . I needed to remove the “title-attribute” because of a firefox(macOs)-bug that would always reload the dropdown after stoping to move the mouse on it.
This would not happen if there was no “title-attribute” anymore. To figure out this already took forever. This code finally make my dropdowns work like they should.
What happens if it isn’t hard coded into the theme and WP seems to be generating them of its own accord? What file do I need to edit?
For the wp_list_categories hack, how would I get the category name to display instead of “View all posts filed under “? Is there a simple hack that I’m not aware of?
Great tip - many thanks
You rock. Great post.
To answer JR, and anybody else wondering, open your header.php and look for replace it with his code.
If there are specifics in your brackets, make sure to include them in his code in addition to echo=0
Mine looks like this: $clean_page_list = wp_list_pages(’title_li=&depth=2&echo=0′);
meant to say look for the php calling wp_list_pages() …the php code got cut out.
Good tip. Thanks.
Those who aren’t comfortable editing their theme files can use the Remove Title Attributes plugin to solve this problem.
Tasty… RegExp is not my bag!
Cool exactly what i needed. Thanks!
Thank you for this awesome snippet of code. One of my picky clients did not want the titles to appear on hover. I was using the wp_listpages function, of course and I am glad I came across this site.
What this code does, for those who are not sure, is remove the title that appears when the mouse is over (hover) an item in the list that is generated through the use of the wp_listpages function.
Cheers.
Wow… This is what i was looking for… Now its working finely in my website… Thanks for the useful tip…
I used this code and it removed the titles, but it added the text “Pages” before all of the actual pages and it is messing up my menu, how can I get rid of that text?
Guys can anyone put little bit more information here please!!!
where in the world we should put that piece of code?
sorry , but where to find the two functions wp_list_categories
wp_list_pages
in the theme twentyten !
thanx
thanks for the tip, it totally works
Found this via Google leading me to the WP forums, works great, better than editing core, thanks!
@ Nathan, try this:
wp_list_pages(’echo=0&title_li=’);
note the title_li=
that makes the list title equal to nothing! Cheers
Thank you, this is perfect! Your solution worked for my categories and custom taxonomies. I wish you can also write a code to remove the parent category links =D