Removing a title from wp_list_categories ()

I am trying to remove / replace the title attribute for category items used by WordPress. I am using WordPress 2.9.1 with the following code:

<div id="categories"> <h3>Manufacturers</h3> <ul> <?php str_replace("title=\"View all posts filed under ","",wp_list_categories('use_desc_for_title=0&exclude=1,2,3,4,5&title_li=&hierarchical=1')); ?> </ul> </div> 

From what I read, this method was used for older versions (although I never tried it). I really don't want to hack WordPress interlates or use a JavaScript hack for something so straightforward. Any help is appreciated ...

The update below is what is created from the code above ...

 <div id="categories"> <h3>Manufacturers</h3> <ul> <li class="cat-item cat-item-7"><a href="http://localhost/crosstrainers/?cat=7" title="View all posts filed under Featured">Featured</a> </li> </ul> </div> 
+6
function php wordpress customization
source share
5 answers

If you do not want to use the plugin by removing the code from the Remove Title Attributes plugin , you can see the main function used to remove titles from categories.

open the template / function.php file and paste the following ...

 function wp_list_categories_remove_title_attributes($output) { $output = preg_replace('` title="(.+)"`', '', $output); return $output; } add_filter('wp_list_categories', 'wp_list_categories_remove_title_attributes'); 

this will add a new filter replacing the wp_list_categories function used by wordpress and replace it with the function above.

in your code example

 <div id="categories"> <h3>Manufacturers</h3> <ul> <?php wp_list_categories(); ?> </ul> </div> 

It will be displayed as

  <div id="categories"> <h3>Manufacturers</h3> <ul> <li class="cat-item cat-item-7"><a href="http://localhost/crosstrainers/?cat=7">Featured</a></li> </ul> </div> 

If header = "" has been completely removed. :)

Credits: Tim Holt and his plugin

+9
source share

There is a plugin, perhaps this will help at least take a look at the plugin code.

http://wordpress.org/extend/plugins/remove-title-attributes/

+3
source share

This is a bit late answer on an old post, but there is a much simpler way that does not require plugins or adding to functions.php :

 <?php wp_list_categories('title_li='); ?> 

or, if you use output with other settings:

 <?php $args = array ( 'title_li' => __( '' ), 'hide_empty' => 0, 'show_count' => 1, 'use_desc_for_title' => 0, 'child_of' => 1 ); wp_list_categories( $args ); ?> 
+3
source share

By default, wp_list_categories will include a description of the category in the title attribute, if one exists, or "View all entries submitted under the category" if there is no description.

I do not like to have all the description here. This is what I use in functions.php to set the title attribute:

 function custom_categories_title($output) { $search = '/title=".+"(.*>)(.+)</i'; $replace = "title=\"View all articles filed under $2\"$1$2<"; return preg_replace($search, $replace, $output); } add_filter('wp_list_categories', 'custom_categories_title'); 

If you just want to completely remove the title attribute, you can use

  $search = '/ title=".+"/i'; $replace = ''; 
0
source share

This is probably your best option for those who want to do this without any functions.php functions

Just add this to your template.

  <ul class="nav"> <?php wp_list_categories( array( 'orderby' => 'name', 'taxonomy' => 'product_cat', 'depth' => 1, 'title_li' => '', 'hide_title_if_empty' => true, 'use_desc_for_title' => 0, 'include' => array( 28, 27, 8, 29, 43, 31 ) ) ); ?> </ul> 
0
source share

All Articles