yoast_get_primary_term

Get the primary term name.

Description

(string) yoast_get_primary_term( (string) $taxonomy = 'category', (null) $post = null ); 

Returns (string)

Name of the primary term.

Parameters (2)

0. $taxonomy — Optional. (string) => 'category'
The taxonomy to get the primary term for. Defaults to category.
1. $post — Optional. (null) => null
Post to get the primary term for.

Usage

  1. if ( !function_exists( 'yoast_get_primary_term' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yoast-seo/inc/wpseo-functions.php'; 
  3.  
  4. // Optional. The taxonomy to get the primary term for. Defaults to category. 
  5. $taxonomy = 'category'; 
  6.  
  7. // Optional. Post to get the primary term for. 
  8. $post = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = yoast_get_primary_term($taxonomy, $post); 
  12.  

Defined (1)

The function is defined in the following location(s).

/inc/wpseo-functions.php  
  1. function yoast_get_primary_term( $taxonomy = 'category', $post = null ) { 
  2. $primary_term_id = yoast_get_primary_term_id( $taxonomy, $post ); 
  3.  
  4. $term = get_term( $primary_term_id ); 
  5. if ( ! is_wp_error( $term ) && ! empty( $term ) ) { 
  6. return $term->name; 
  7.  
  8. return '';