Skip to content

Instantly share code, notes, and snippets.

@peterbinks
Created March 4, 2019 01:47
Show Gist options
  • Save peterbinks/ef4f6ee18f8c09fb6aebf68b8f574033 to your computer and use it in GitHub Desktop.
Save peterbinks/ef4f6ee18f8c09fb6aebf68b8f574033 to your computer and use it in GitHub Desktop.
// 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