Created
February 16, 2025 11:22
-
-
Save tdmrhn/152dbd2571c6d206faf561e725632723 to your computer and use it in GitHub Desktop.
Show only parent taxonomy terms in blog single post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('get_the_terms', function($terms, $post_id) { | |
if (is_single() && get_post_type($post_id) === 'post') { | |
return array_filter($terms, fn($term) => $term->parent === 0); | |
} | |
return $terms; | |
}, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment