do_action_ref_array( 'send_headers', WP $this )

Fires once the requested HTTP headers for caching, content type, etc. have been sent.


Parameters Parameters

$this

(WP) Current WordPress environment instance (passed by reference).


Top ↑

More Information More Information

This action hook is used to add additional headers to the outgoing HTTP response.


Top ↑

Source Source

File: wp-includes/class-wp.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Collins Mbaka

    As an example: HTML5 Boilerplate provides an X-UA-Compatible meta element by default. This element breaks validation but can be moved to a header. Adding the following to functions.php fixes the validation issue and provides IE users a better experience.

    add_action( 'send_headers', 'add_header_xua' );
    function add_header_xua() {
    	header( 'X-UA-Compatible: IE=edge,chrome=1' );
    }
    
  2. Skip to note 2 content
    Contributed by stevenlinx

    Example migrated from Codex:

    As an example: HTML5 Boilerplate provides an X-UA-Compatible meta element by default. This element breaks validation, but can be moved to a header. Adding the following to functions.php fixes the validation issue and provides IE users a better experience.

    add_action( 'send_headers', 'add_header_xua' );
    function add_header_xua() {
    	header( 'X-UA-Compatible: IE=edge,chrome=1' );
    }
    
  3. Skip to note 3 content
    Contributed by wp_kc

    Example of how to conditionally send a header, replacing previously set header, if any…

    /**
     * Send "X-Robots-Tag: noindex, nofollow" header if not a public web site. 
     * If WP_DEBUG is true, treat web site as if it is non-public.
     */
    add_action( 'send_headers', function() {
    	if ( '0' != get_option( 'blog_public' ) || ( defined( 'WP_DEBUG' ) && true == WP_DEBUG ) ) {
    		/**
    		 * Tell robots not to index or follow
    		 * Set header replace parameter to true
    		 */
    		header( 'X-Robots-Tag: noindex, nofollow', true );
    	}
    }, 99 );  // Try to execute last with priority set to 99

You must log in before being able to contribute a note or feedback.