Skip to content

Instantly share code, notes, and snippets.

@igorveremsky
Created October 11, 2017 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorveremsky/5b8ba76fce5eec33692202320a77e192 to your computer and use it in GitHub Desktop.
Save igorveremsky/5b8ba76fce5eec33692202320a77e192 to your computer and use it in GitHub Desktop.
Get Primary Category for Post Wordpress, Yoast
<?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