Last active
April 19, 2017 15:32
-
-
Save hearvox/a2863807b3d528f30dc080670f96e8eb to your computer and use it in GitHub Desktop.
Use Yoast SEO (WordPress plugin) Primary Category only on Category taxonomy.
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 | |
/* 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' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.