The extra_{$context}_headers WordPress PHP filter allows you to add extra file headers based on a specific context.
Usage
add_filter('extra_{$context}_headers', 'my_custom_headers'); function my_custom_headers($extra_context_headers) { // Your custom code here return $extra_context_headers; }
Parameters
- $extra_context_headers (array): An array of extra headers for the given context. Empty array by default.
More information
See WordPress Developer Resources: extra_{$context}_headers
Examples
Add extra headers for theme
Add custom headers to the theme’s style.css
file:
add_filter('extra_theme_headers', 'my_custom_theme_headers'); function my_custom_theme_headers($extra_headers) { $extra_headers[] = 'Theme Version'; return $extra_headers; }
Add extra headers for plugin
Add custom headers to a plugin’s main file:
add_filter('extra_plugin_headers', 'my_custom_plugin_headers'); function my_custom_plugin_headers($extra_headers) { $extra_headers[] = 'Plugin Version'; return $extra_headers; }
Add multiple extra headers for theme
Add multiple custom headers to the theme’s style.css
file:
add_filter('extra_theme_headers', 'my_multiple_custom_theme_headers'); function my_multiple_custom_theme_headers($extra_headers) { $extra_headers[] = 'Theme Version'; $extra_headers[] = 'Theme Author'; return $extra_headers; }
Add multiple extra headers for plugin
Add multiple custom headers to a plugin’s main file:
add_filter('extra_plugin_headers', 'my_multiple_custom_plugin_headers'); function my_multiple_custom_plugin_headers($extra_headers) { $extra_headers[] = 'Plugin Version'; $extra_headers[] = 'Plugin Author'; return $extra_headers; }
Add conditional extra headers for theme
Add custom headers to the theme’s style.css
file, but only for a specific theme:
add_filter('extra_theme_headers', 'my_conditional_custom_theme_headers'); function my_conditional_custom_theme_headers($extra_headers) { $theme = wp_get_theme(); if ($theme->get('Name') == 'My Custom Theme') { $extra_headers[] = 'Theme Version'; } return $extra_headers; }