This tutorial will show you how to easily remove the WordPress category title attribute from your WordPress post categories menu, this is the little pop-up text you see when hovering over a category link in your browser. This is a feature I always find myself using over and over again so wrote it into a neat WordPress function to share with you all.
The title attribute is best used to add optional advisory information to a page element. WordPress’s default behaviour is to add title attributes to pretty much every link that it can, whether it has advisory information about it to offer or not. For example, links in category menus, page lists and archive menus simply duplicate the link text in their title attributes. This helps no one but hinders some users and removing these title attributes will also help overall website accessibility.
Step 1: Add Our Remove WordPress Category Title WordPress Functionk
Firstly you will want to open your current themes functions.php file then copy the code block below and paste it into your functions.php file at the bottom, close and save your functions.php file.
//-------------------- [ Remove Category Title Attribute ] -------------------// function category_no_title() { // fetch the original category html output list $categories = wp_list_categories('echo=0&sort_column=menu_order&depth=3&title_li='); // removes the title attribute within the category list menu html output $categories = preg_replace('/title="(.*?)"/','',$categories); // outputs the new category list without the html title attribute echo $categories; }
Step 2: Using The Function Within Your WordPress Theme
Copy and paste the code below into your WordPress theme. You can search for instances of the wp_list_categories() function within your theme and replace it with the code snippet below. Some WordPress themes that show post categories as dropdowns in the header the code you will need to replace will probably be located in your WordPress themes header.php file.
<?php category_no_title() ?>
You should now have more accessible category menus without having the annoying attribute title popping up when hovering over a post category menu link.
Leave a Reply
You must be logged in to post a comment.