Sometimes you may need to hide certain tags and categories from your widgets. In this post, I will explain you how to hide unwanted terms using wordpress filters.

First open your functions.php file in your theme folder. This is the main script file where we can add our customizations.

Now add this block of code in your functions file:

function shailan_filter_terms( $exclusions, $args ){
	// IDs of terms to be excluded
	$exclude = "3,257"; // CHANGE THIS TO IDs OF YOUR TERMS
	// Generation of exclusion SQL code
	$exterms = wp_parse_id_list( $exclude );
	foreach ( $exterms as $exterm ) {
			if ( empty($exclusions) )
					$exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
					$exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' ';
	// Closing bracket
	if ( !empty($exclusions) )
		$exclusions .= ')';
	// Return our SQL statement
	return $exclusions;

// Finally hook up our filter
add_filter( 'list_terms_exclusions', 'shailan_filter_terms', 10, 2 );

After you add the code, don’t forget to update the exclude id list in the code. That way, it will exclude correct categories or tags from your widgets.

Remember to SAVE and UPLOAD your file after you edit it.
Now your widgets will automatically exclude those terms.

Deal Notice: We are using A2 hosting for all of our websites, and we are really happy with their service. So we wanted to share you this discount link for you to try it out. If you get a hosting using this link, you will also help us build better content for you: SSD Hosting - 300% Faster Than Standard Hard Drives