Add Custom Authorization Header to REST API Requests
Last updated 1 month ago
PHP
function add_custom_authorization_header($request) {
$headers = $request->get_headers();
// Add custom authorization header
$headers['Authorization'] = 'Bearer ' . get_option('my_custom_api_token');
$request->set_headers($headers);
return $request;
}
add_filter('rest_request_before_callbacks', 'add_custom_authorization_header');
All code snippets are licensed GPLv2 or later unless otherwise stated.