get_primary_term(); // If we have one, return it. if ( $wpseo_primary_term ) { return get_term( $wpseo_primary_term ); } } // We don't have a primary, so let's get all the terms. $terms = get_the_terms( $post_id, $taxonomy ); // Bail if no terms. if ( ! $terms || is_wp_error( $terms ) ) { return false; } // Return the first term. return $terms[0]; }