single_month_title( string $prefix = '', bool $display = true )
Display or retrieve page title for post archive based on date.
Description Description
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.
Parameters Parameters
- $prefix
-
(string) (Optional) What to display before the title.
Default value: ''
- $display
-
(bool) (Optional) Whether to display or retrieve title.
Default value: true
Return Return
(string|void) Title when retrieving.
Source Source
File: wp-includes/general-template.php
function single_month_title( $prefix = '', $display = true ) { global $wp_locale; $m = get_query_var( 'm' ); $year = get_query_var( 'year' ); $monthnum = get_query_var( 'monthnum' ); if ( ! empty( $monthnum ) && ! empty( $year ) ) { $my_year = $year; $my_month = $wp_locale->get_month( $monthnum ); } elseif ( ! empty( $m ) ) { $my_year = substr( $m, 0, 4 ); $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) ); } if ( empty( $my_month ) ) { return false; } $result = $prefix . $my_month . $prefix . $my_year; if ( ! $display ) { return $result; } echo $result; }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
0.71 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Month and Year on New Lines
Displays the title, placing month and year on new lines.
Output is following 2 lines.