Fires the wp_body_open action.
Description
See ‘wp_body_open’.
Source
function wp_body_open() {
/**
* Triggered after the opening body tag.
*
* @since 5.2.0
*/
do_action( 'wp_body_open' );
}
Hooks
- do_action( ‘wp_body_open’ )
Triggered after the opening body tag.
Changelog
| Version | Description |
|---|---|
| 5.2.0 | Introduced. |
WordPress theme developers should use `
wp_head()`, `wp_body_open()` and `wp_footer()` functions in their themes (read this for more information).The new WordPress theme structure:
Don’t forget backward compatibility.
I Think This is the best way for add
wp_body_open();function for backwards compatibilityStep 1 : Checked if function is exits, if not exits then make a function called
wp_body_open();Example:
Then put the function after the body tag.
Example:
How can I use this to my advantage as a plugin developer? How to make sure my code is included if the WP version is 5.2+ but the theme is older and/or does not include
wp_body_open?Here is a working solution suggested by @danieliser on this ticket answer.
This way if you want to include code from your plugin just after the body tag opened by a theme that is up to date with good practices, and if it’s not, your code gets included the old way with
wp_footer.Custom Theme Hooks
Many themes use their own custom actions at the beginning of body tag. They should consider migrating to the core wp_body_open action.
For backwards compatibility, when injecting custom code, theme developers can use conditional logic to hook to the right action