このエントリーをはてなブックマークに追加

Modifying HTTP response header in your WordPress site

Though Google recommends responsive web design most, they also support sites which produce different HTML on the same URL depending on user-agent information. My site is the latter. Google’s recommendation to sites like mine is to use ‘Vary’ HTTP header.

But with standard installation, WordPress doesn’t set ‘Vary’ HTTP field in HTTP response header. So I need to insert it in the header by modifying functions.php.

To insert HTTP header fields, write a filter function for ‘wp_headers’ in your functions.php.

function add_vary_header($headers) {
    $headers['Vary'] = 'User-Agent';
    return $headers;
}

add_filter('wp_headers', 'add_vary_header');

You can also remove unwanted header fields by unsetting them. (related information)

function remove_x_pingback($headers) {
    unset($headers['X-Pingback']);
    return $headers;
}

add_filter('wp_headers', 'remove_x_pingback');

These changes are applied to your WordPress site except admin pages.

6 thoughts on “Modifying HTTP response header in your WordPress site

  1. Pingback: A Comparison of Methods for Building Mobile-Optimized Websites

  2. Pingback: A Comparison of Methods for Building Mobile-Optimized Websites « All You Need Online

  3. Pingback: A Comparison of Methods for Building Mobile-Optimized Websites | iDevie

  4. Pingback: A Comparison of Methods for Building Mobile-Optimized Websites

  5. Pingback: A Comparison of Methods for Building Mobile-Optimized WebsitesGood looking DESIGN | Good looking DESIGN

  6. Pingback: A Comparison of Methods for Building Mobile-Optimized Websites » 7D Interactive : Innovative Web Development & SEO in Maryland

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt="">