Created
March 4, 2019 01:47
-
-
Save peterbinks/ef4f6ee18f8c09fb6aebf68b8f574033 to your computer and use it in GitHub Desktop.
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
// Add to function.php | |
function taxo_primary_term_name($taxo){ | |
$wpseo_primary_term = new WPSEO_Primary_Term($taxo, get_the_ID()); | |
$wpseo_primary_term = $wpseo_primary_term->get_primary_term(); | |
$cat = get_the_category(); | |
if ( $wpseo_primary_term ) { // Return yoast primary category | |
return $wpseo_primary_term = get_term($wpseo_primary_term)->name; | |
} | |
else { // Otherwise reture the first normal category | |
// Return the first term. | |
return $cat[0]->cat_name; | |
} | |
} | |
// Put in themplate where you want it to show up | |
<?php echo taxo_primary_term_name('category'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment