Created
March 20, 2024 22:41
-
-
Save sybrew/8864ee7743121715b72697f41b62e68a to your computer and use it in GitHub Desktop.
Gets primary term name automatically from any post type for The SEO Framework WordPress plugin.
This file contains 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 | |
// Don't include the PHP opening tag if PHP is already open. | |
function get_primary_term_name( $post_id ) { | |
$taxonomies = array_keys( array_filter( | |
tsf()->taxonomy()->get_hierarchical( 'objects', get_post_type( $post_id ) ), | |
'is_taxonomy_viewable', | |
) ); | |
$taxonomy = reset( $taxonomies ); | |
return $taxonomy | |
? ( tsf()->data()->plugin()->post()->get_primary_term( $post_id, $taxonomy )->name ?? '' ) | |
: ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment