WordPress at a glance

single_month_title() WP 1.0

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

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.

  • Global. WP_Locale. $wp_locale

No Hooks.

Return

String/null. Title when retrieving.

Usage

single_month_title( $prefix, $display );
$prefix(string)
What to display before the title.
Default: ''
$display(true/false)
Whether to display or retrieve title.
Default: true

Code of single_month_title: wp-includes/general-template.php VER 5.0.1

<?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;
}

Related Functions

From tag: title (of post page)

More from category: Other Theme Functions

More from Template Tags: Posts, Pages, ...

No comments
    Hello, !     Log In . Register