Title: nocache_headers
Published: April 25, 2014
Last modified: February 24, 2026

---

# nocache_headers()

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#see-also)
 * [More Information](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#wp--skip-link--target)

Sets the HTTP headers to prevent caching for the different browsers.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#description)󠁿

Different browsers support different nocache headers, so several headers must be
sent so that all of them get the point that no caching should occur.

### 󠀁[See also](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#see-also)󠁿

 * [wp_get_nocache_headers()](https://developer.wordpress.org/reference/functions/wp_get_nocache_headers/)

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#more-information)󠁿

##### 󠀁[Usage:](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#usage)󠁿

    ```php
    nocache_headers();
    ```

## 󠀁[Source](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#source)󠁿

    ```php
    function nocache_headers() {
    	if ( headers_sent() ) {
    		return;
    	}

    	$headers = wp_get_nocache_headers();

    	unset( $headers['Last-Modified'] );

    	header_remove( 'Last-Modified' );

    	foreach ( $headers as $name => $field_value ) {
    		header( "{$name}: {$field_value}" );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/functions.php#L1538)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/functions.php#L1538-L1552)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_nocache_headers()](https://developer.wordpress.org/reference/functions/wp_get_nocache_headers/)`wp-includes/functions.php` |

Gets the HTTP header information to prevent caching.

  |

| Used by | Description | 
| [_jsonp_wp_die_handler()](https://developer.wordpress.org/reference/functions/_jsonp_wp_die_handler/)`wp-includes/functions.php` |

Kills WordPress execution and displays JSONP response with an error message.

  | 
| [_xml_wp_die_handler()](https://developer.wordpress.org/reference/functions/_xml_wp_die_handler/)`wp-includes/functions.php` |

Kills WordPress execution and displays XML response with an error message.

  | 
| [_json_wp_die_handler()](https://developer.wordpress.org/reference/functions/_json_wp_die_handler/)`wp-includes/functions.php` |

Kills WordPress execution and displays JSON response with an error message.

  | 
| [wp_start_scraping_edited_file_errors()](https://developer.wordpress.org/reference/functions/wp_start_scraping_edited_file_errors/)`wp-includes/load.php` |

Starts scraping edited file errors.

  | 
| [WP_Customize_Manager::customize_preview_init()](https://developer.wordpress.org/reference/classes/wp_customize_manager/customize_preview_init/)`wp-includes/class-wp-customize-manager.php` |

Prints JavaScript settings.

  | 
| [auth_redirect()](https://developer.wordpress.org/reference/functions/auth_redirect/)`wp-includes/pluggable.php` |

Checks if a user is logged in, if not it redirects them to the login page.

  | 
| [WP::handle_404()](https://developer.wordpress.org/reference/classes/wp/handle_404/)`wp-includes/class-wp.php` |

Set the Headers for 404, if nothing is found for requested URL.

  | 
| [wp_not_installed()](https://developer.wordpress.org/reference/functions/wp_not_installed/)`wp-includes/load.php` |

Redirects to the installer if WordPress is not installed.

  | 
| [_default_wp_die_handler()](https://developer.wordpress.org/reference/functions/_default_wp_die_handler/)`wp-includes/functions.php` |

Kills WordPress execution and displays HTML page with an error message.

  | 
| [_ajax_wp_die_handler()](https://developer.wordpress.org/reference/functions/_ajax_wp_die_handler/)`wp-includes/functions.php` |

Kills WordPress execution and displays Ajax response with an error message.

  | 
| [_xmlrpc_wp_die_handler()](https://developer.wordpress.org/reference/functions/_xmlrpc_wp_die_handler/)`wp-includes/functions.php` |

Kills WordPress execution and displays XML response with an error message.

  |

[Show 6 more](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/nocache_headers/?output_format=md#comment-content-4096)
 2.   [iSaumya](https://profiles.wordpress.org/isaumya/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/nocache_headers/#comment-4096)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnocache_headers%2F%23comment-4096)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnocache_headers%2F%23comment-4096)
 4. Use nocache_headers to add custom headers to `wp-admin` pages. Example code:
 5.     ```php
        add_filter( 'nocache_headers', function() {
            return array(
                'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0, some-custom-thing',
                'Pragma'        => 'no-cache',
                'Expires'       => gmdate( 'D, d M Y H:i:s \G\M\T', time() )
            );
        } );
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnocache_headers%2F%3Freplytocom%3D4096%23feedback-editor-4096)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fnocache_headers%2F)
before being able to contribute a note or feedback.