Created
October 11, 2017 13:58
-
-
Save igorveremsky/5b8ba76fce5eec33692202320a77e192 to your computer and use it in GitHub Desktop.
Get Primary Category for Post Wordpress, Yoast
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 | |
$primary_cat_id = get_post_meta(get_the_ID(), '_yoast_wpseo_primary_category', true); | |
if ( $primary_cat_id != null ) { | |
$category = get_category($primary_cat_id); | |
} else { | |
$categories = get_the_category(); | |
$category = $categories[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment