I've excluded a specific category from displaying on the Blog, but the titles of the posts are still showing down the right hand side in the 'Archive Widget'

Hi, I’ve excluded a specific category from displaying on the Blog, but the titles of the posts are still showing down the right hand side in the ‘Archive Widget’ and I don’t know how to get rid of them! I found a previous post and used the code below but it didn’t work, I hope you can help!

add_filter( 'widget_categories_args', 'wpsites_exclude_widget_category', 99 );
add_filter( 'widget_categories_dropdown_args', 'wpsites_exclude_widget_category', 99 );
function wpsites_exclude_widget_category( $cat_args ) {
$cat_args['exclude'] = '5';
return $cat_args;

I’ll put the URL in a secure note as it’s on a temp link.

Thanks!

Hello @core365,

Thanks for writing in!

You may need to update your code and use this instead:

//Hide categories from WordPress category widget
function exclude_widget_categories($args){
    $exclude = "5";
    $args["exclude"] = $exclude;
    return $args;
}
add_filter("widget_categories_args","exclude_widget_categories"); 
add_filter( "widget_categories_dropdown_args", "exclude_widget_categories");

Just make sure that the $exclude = "5"; is the exact category ID. To find out the category ID, please check this out:

Hi @ruenel,

Thanks, however nothing happens after I’ve added the code into the functions.php file! The category ID is correct, as I used code to exclude showing the posts for category 5 from the blog page - the only entry in the ‘Recent Posts’ widget should be ‘New Year, New Job, Time to Kickstart…’, the names under that are posts from category 5 which shouldn’t be showing. Ah, I’ve just realised, I originally asked for the category to be excluded from the ‘Archives Widget’ and I meant the ‘Recent Posts’ one! That’s probably why the code isn’t working then - is that right?!! Oopsie! Sorry, it’s the ‘Recent Posts’ I’d like to exclude the category from please!

Thanks!

Hi @core365,

Thank you for the clarification. Recent post widget is not a theme fuction but rather part of the wordpress core. Please check this thread instead for guidance.

Hope this helps.

Hi @lely,

Sorry, I’m a bit confused! Am I understanding it correctly, from what you’ve said, the ‘Archive Widget’ is included in the theme function and that’s why Ruenel kindly gave me the code, whereas the ‘Recent Post Widget’ isn’t included in the theme function?

I’ve used the code from the link you supplied, thank you, and that’s worked a bit differently, instead of excluding a category, it’s code to only show certain categories which works out just the same!

Thanks!

Hi @core365,

I am sorry for the confusion. Both archive widget and recent post widget that you can find on Appearance > Widget are not part of the theme but rather of the wordpress core. Other widgets in there are from plugins. Since you have a code already in there, @ruenel help adjusted it. Unfortunately, we need you to understand that support limitations are for functions/feature of the theme. Other customization is also outside the scope of our support because of potential issues that may arise in the future. But rest assured we always try our best to point you in the right direction. Thank you for understanding.

Hi @lely,

Ah ok! Thanks for your help!

You’re welcome, @core365.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.