wp_get_nocache_headers() WordPress Function

The wp_get_nocache_headers() function is used to prevent caching of a page or post in WordPress. This function is typically used when a page or post is updated frequently and you want to make sure that users are always seeing the most up-to-date version.

wp_get_nocache_headers() #

Get the header information to prevent caching.


Description

The several different headers cover the different ways cache prevention is handled by different browsers


Top ↑

Return

(array) The associative array of header names and field values.


Top ↑

Source

File: wp-includes/functions.php

function wp_get_nocache_headers() {
	$headers = array(
		'Expires'       => 'Wed, 11 Jan 1984 05:00:00 GMT',
		'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
	);

	if ( function_exists( 'apply_filters' ) ) {
		/**
		 * Filters the cache-controlling headers.
		 *
		 * @since 2.8.0
		 *
		 * @see wp_get_nocache_headers()
		 *
		 * @param array $headers {
		 *     Header names and field values.
		 *
		 *     @type string $Expires       Expires header.
		 *     @type string $Cache-Control Cache-Control header.
		 * }
		 */
		$headers = (array) apply_filters( 'nocache_headers', $headers );
	}
	$headers['Last-Modified'] = false;
	return $headers;
}


Top ↑

Changelog

Changelog
VersionDescription
2.8.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.

Show More
Show More