Category list on sidebar widget will display all categories on post category hierarchy by default. However, we do not want to display all of them for some reason. Here is simple technique to achieve this goal.
Find category IDs
First thing to do is to find out all category IDs that we don't want them to show on the sidebar. Run the following script against WordPress MySQL database.
SELECT t.term_id catID,t.name FROM wp_terms t
join wp_term_taxonomy tax on tax.term_id=t.term_id
where tax.taxonomy='category'
Snippets
//Hide categories from WordPress category widget
function exclude_widget_categories($args){
$exclude = "4,6,7,8,9,10,13,14,15,16";
$args["exclude"] = $exclude;
return $args;
}
add_filter("widget_categories_args","exclude_widget_categories");
Apply the snippets
There are many ways to apply the snippets. You could add it to theme functions.php file or using snippets plugin to apply the snippets code. In my case, I'm using snippets to apply the code. This way is better organized for reusing the snippets.
Last words, This is the simplest way to contorl the category list on sidebar, but you may use other ways to control the category list on sidebar, for instance, find a proper plugin or write your own plugin to achieve it.
9,600 total views, 2 views today
Comments
What’s up, I wish for to subscribe for this blog to take most
recent updates, so where cann i do it please
help out.
@Lilia To keep posted, please register here: https://blog.hostlike.com/register/