Title: How to modify HTTP header?
Last modified: July 14, 2024

---

# How to modify HTTP header?

 *  Resolved [slolo](https://wordpress.org/support/users/slolo/)
 * (@slolo)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/how-to-modify-http-header/)
 * Hello,
 * I am trying to modify http headers with your plugin.
 * So, I have created a simple snippet which do this:
 *     ```wp-block-code
       add_filter('wp_headers', 'my_custom_headers');function my_custom_headers($headers) {	// Add X-XSS-Protection header	if (!isset($headers['X-XSS-Protection'])) {		$headers['X-XSS-Protection'] = '1; mode=block;';	}	// Add X-Content-Type-Options header	if (!isset($headers['X-Content-Type-Options'])) {		$headers['X-Content-Type-Options'] = 'nosniff';	}	return $headers;}
       ```
   
 * But, $headers variables only contain “Content-Type” value.
 * In fact I would like to be able to check if headers have already being sent (
   from .htaccess by example) and be able to modify them.
 * So, what is the way to get http headers in order to control them with WPCode 
   snippet?
 * Thanks in advance for your help and have a nice day.

Viewing 1 replies (of 1 total)

 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/how-to-modify-http-header/#post-17889462)
 * Hi [@slolo](https://wordpress.org/support/users/slolo/),
 * WPCode does not change anything in the way the `wp_headers` filter works, we 
   use an early hook (plugins_loaded) to load the snippet if you use the location“
   Run Everywhere” so you should be able to send headers at that time as it runs
   before any output is made by PHP.
 * The `wp_headers` filter will only return the headers that have been set through
   WordPress but if you add a PHP header by directly using the PHP `header` function
   you will not see that reflected in the `wp_headers` filter. You can see how that
   filter is used in the source of WordPress core: [https://github.com/WordPress/wordpress-develop/blob/6.5/src/wp-includes/class-wp.php#L558-L558](https://github.com/WordPress/wordpress-develop/blob/6.5/src/wp-includes/class-wp.php#L558-L558)
 * Regarding seeing other headers you may try to use the PHP function [getallheaders](https://www.php.net/manual/en/function.getallheaders.php)
   or similar functions. This is not specific to WPCode or even WordPress.
 * Lastly, depending on what you want to do with these headers please consider that
   if your site uses any type of Page Cache, the headers you set in PHP will not
   be reflected in the cached version of the pages as that is going to be a static
   version of the page.

Viewing 1 replies (of 1 total)

The topic ‘How to modify HTTP header?’ is closed to new replies.

 * ![](https://ps.w.org/insert-headers-and-footers/assets/icon-256x256.png?rev=2758516)
 * [WPCode - Insert Headers and Footers + Custom Code Snippets - WordPress Code Manager](https://wordpress.org/plugins/insert-headers-and-footers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-headers-and-footers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-headers-and-footers/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-headers-and-footers/reviews/)

## Tags

 * [headers](https://wordpress.org/support/topic-tag/headers/)
 * [HTTP](https://wordpress.org/support/topic-tag/http/)
 * [Modify](https://wordpress.org/support/topic-tag/modify/)

 * 1 reply
 * 2 participants
 * Last reply from: [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * Last activity: [1 year, 10 months ago](https://wordpress.org/support/topic/how-to-modify-http-header/#post-17889462)
 * Status: resolved