single_term_title

Display or retrieve page title for taxonomy term archive.

Description

(string|void) single_term_title( (string) $prefix = '', (bool) $display = true ); 

Useful for taxonomy term template files for displaying the taxonomy term page title. The prefix does not automatically place a space between the prefix, so if there should be a space, the parameter value will need to have it at the end.

Returns (string|void)

Title when retrieving.

Parameters (2)

0. $prefix — Optional. (string) => ''
What to display before the title.
1. $display — Optional. (bool) => true
Optional, default is true. Whether to display or retrieve title.

Usage

  1. if ( !function_exists( 'single_term_title' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Optional. What to display before the title. 
  5. $prefix = ''; 
  6.  
  7. // Optional, default is true. Whether to display or retrieve title. 
  8. $display = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = single_term_title($prefix, $display); 
  12.  

Defined (1)

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

/wp-includes/general-template.php  
  1. function single_term_title( $prefix = '', $display = true ) { 
  2. $term = get_queried_object(); 
  3.  
  4. if ( !$term ) 
  5. return; 
  6.  
  7. if ( is_category() ) { 
  8. /** 
  9. * Filters the category archive page title. 
  10. * @since 2.0.10 
  11. * @param string $term_name Category name for archive being displayed. 
  12. */ 
  13. $term_name = apply_filters( 'single_cat_title', $term->name ); 
  14. } elseif ( is_tag() ) { 
  15. /** 
  16. * Filters the tag archive page title. 
  17. * @since 2.3.0 
  18. * @param string $term_name Tag name for archive being displayed. 
  19. */ 
  20. $term_name = apply_filters( 'single_tag_title', $term->name ); 
  21. } elseif ( is_tax() ) { 
  22. /** 
  23. * Filters the custom taxonomy archive page title. 
  24. * @since 3.1.0 
  25. * @param string $term_name Term name for archive being displayed. 
  26. */ 
  27. $term_name = apply_filters( 'single_term_title', $term->name ); 
  28. } else { 
  29. return; 
  30.  
  31. if ( empty( $term_name ) ) 
  32. return; 
  33.  
  34. if ( $display ) 
  35. echo $prefix . $term_name; 
  36. else 
  37. return $prefix . $term_name;