Skip to content

Instantly share code, notes, and snippets.

@hearvox
Last active April 19, 2017 15:32
Show Gist options
  • Save hearvox/a2863807b3d528f30dc080670f96e8eb to your computer and use it in GitHub Desktop.
Save hearvox/a2863807b3d528f30dc080670f96e8eb to your computer and use it in GitHub Desktop.
Use Yoast SEO (WordPress plugin) Primary Category only on Category taxonomy.
<?php
/* Use Yoast SEO's Primary Category feature only on Categories. */
function myprefix_yoast_primary_tax( $all_taxonomies ) {
$args = array( 'name' => 'category' );
$all_taxonomies = get_taxonomies( $args, 'objects' );
return $all_taxonomies;
}
add_filter('wpseo_primary_term_taxonomies', 'myprefix_yoast_primary_tax' );
?>
@hearvox
Copy link
Author

hearvox commented Apr 19, 2017

Yoast defaults to using its Primary Category feature on all hierarchical taxonomies, including custom ones. This script uses the plugin's filter (/admin/class-primary-term-admin.php) to return only the object for the 'category' taxonomy, thereby applying the feature only to that taxonomy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment