Skip to content

Snippet: Exclude Terms from Categories Meta

add_filter( 'wp_get_object_terms', function( $terms ) {
	if ( $terms ) {
		$excluded_terms = array( 100, 40 ); // array of term ID's to exclude
		foreach( $terms as $key => $term ) {
			if ( in_array( $term->term_id, $excluded_terms ) ) {
				unset($terms[$key]);
			}
		}
	}
	return $terms;
}, 10, 3 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top