Title: WP_REST_Request::canonicalize_header_name
Published: December 9, 2015
Last modified: May 20, 2026

---

# WP_REST_Request::canonicalize_header_name( string $key ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/?output_format=md#changelog)

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

Canonicalizes the header name.

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

Ensures that header names are always treated the same regardless of source. Header
names are always case-insensitive.

Note that we treat `-` (dashes) and `_` (underscores) as the same character, as 
per header parsing rules in both Apache and nginx.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/?output_format=md#parameters)󠁿

 `$key`stringrequired

Header name.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/?output_format=md#return)󠁿

 string Canonicalized name.

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

    ```php
    public static function canonicalize_header_name( $key ) {
    	$key = strtolower( $key );
    	$key = str_replace( '-', '_', $key );

    	return $key;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/class-wp-rest-request.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/rest-api/class-wp-rest-request.php#L194)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/rest-api/class-wp-rest-request.php#L194-L199)

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

| Used by | Description | 
| [WP_REST_Server::get_target_hints_for_link()](https://developer.wordpress.org/reference/classes/wp_rest_server/get_target_hints_for_link/)`wp-includes/rest-api/class-wp-rest-server.php` |

Gets the target hints for a REST API Link.

  | 
| [WP_REST_Request::get_header_as_array()](https://developer.wordpress.org/reference/classes/wp_rest_request/get_header_as_array/)`wp-includes/rest-api/class-wp-rest-request.php` |

Retrieves header values from the request.

  | 
| [WP_REST_Request::set_header()](https://developer.wordpress.org/reference/classes/wp_rest_request/set_header/)`wp-includes/rest-api/class-wp-rest-request.php` |

Sets the header on request.

  | 
| [WP_REST_Request::add_header()](https://developer.wordpress.org/reference/classes/wp_rest_request/add_header/)`wp-includes/rest-api/class-wp-rest-request.php` |

Appends a header value for the given header.

  | 
| [WP_REST_Request::remove_header()](https://developer.wordpress.org/reference/classes/wp_rest_request/remove_header/)`wp-includes/rest-api/class-wp-rest-request.php` |

Removes all values for a header.

  | 
| [WP_REST_Request::get_header()](https://developer.wordpress.org/reference/classes/wp_rest_request/get_header/)`wp-includes/rest-api/class-wp-rest-request.php` |

Retrieves the given header from the request.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_request/canonicalize_header_name/?output_format=md#)

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

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

## User Contributed Notes

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