single_month_title

Display or retrieve page title for post archive based on date.

Description

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

Useful for when the template only needs to display the month and year, if either are available. 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_month_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_month_title($prefix, $display); 
  12.  

Defined (1)

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

/wp-includes/general-template.php  
  1. function single_month_title($prefix = '', $display = true ) { 
  2. global $wp_locale; 
  3.  
  4. $m = get_query_var('m'); 
  5. $year = get_query_var('year'); 
  6. $monthnum = get_query_var('monthnum'); 
  7.  
  8. if ( !empty($monthnum) && !empty($year) ) { 
  9. $my_year = $year; 
  10. $my_month = $wp_locale->get_month($monthnum); 
  11. } elseif ( !empty($m) ) { 
  12. $my_year = substr($m, 0, 4); 
  13. $my_month = $wp_locale->get_month(substr($m, 4, 2)); 
  14.  
  15. if ( empty($my_month) ) 
  16. return false; 
  17.  
  18. $result = $prefix . $my_month . $prefix . $my_year; 
  19.  
  20. if ( !$display ) 
  21. return $result; 
  22. echo $result;