Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_get_random_header_data() WordPress Function

The get_random_header_data() WordPress function returns an array of random header data. This function can be used to randomly select a header image or text for your WordPress site.

_get_random_header_data() #

Gets random header image data from registered images in theme.


Return

(object)


Top ↑

Source

File: wp-includes/theme.php

function _get_random_header_data() {
	global $_wp_default_headers;
	static $_wp_random_header = null;

	if ( empty( $_wp_random_header ) ) {
		$header_image_mod = get_theme_mod( 'header_image', '' );
		$headers          = array();

		if ( 'random-uploaded-image' === $header_image_mod ) {
			$headers = get_uploaded_header_images();
		} elseif ( ! empty( $_wp_default_headers ) ) {
			if ( 'random-default-image' === $header_image_mod ) {
				$headers = $_wp_default_headers;
			} else {
				if ( current_theme_supports( 'custom-header', 'random-default' ) ) {
					$headers = $_wp_default_headers;
				}
			}
		}

		if ( empty( $headers ) ) {
			return new stdClass;
		}

		$_wp_random_header = (object) $headers[ array_rand( $headers ) ];

		$_wp_random_header->url = sprintf(
			$_wp_random_header->url,
			get_template_directory_uri(),
			get_stylesheet_directory_uri()
		);

		$_wp_random_header->thumbnail_url = sprintf(
			$_wp_random_header->thumbnail_url,
			get_template_directory_uri(),
			get_stylesheet_directory_uri()
		);
	}

	return $_wp_random_header;
}


Top ↑

Changelog

Changelog
VersionDescription
3.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.