get_primary_category( $post ); if ( $primary_category !== false && $primary_category !== $category->cat_ID ) { $category = \get_category( $primary_category ); } return $category; } /** * Get the id of the primary category. * * @codeCoverageIgnore It justs wraps a dependency. * * @param WP_Post $post The post in question. * * @return int Primary category id. */ protected function get_primary_category( $post ) { $primary_term = new WPSEO_Primary_Term( 'category', $post->ID ); return $primary_term->get_primary_term(); } }