do_action( 'wp_body_open' )
Triggered after the opening tag.
Description Description
Source Source
Changelog Changelog
| Version | Description |
|---|---|
| 5.2.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Backward Compatibility
A conditional check can make it compatible with older WordPress versions.
<!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>"> <?php wp_head(); ?> </head> <body <?php body_class(); ?>> <?php if ( function_exists( 'wp_body_open' ) ) { wp_body_open(); } ?> <?php wp_footer(); ?> </body> </html>Expand full source codeCollapse full source code
For More Information: https://make.wordpress.org/themes/2019/03/29/addition-of-new-wp_body_open-hook/
Basic usage:
function custom_body_open_code() { return '<!-- some code -->'; } add_action( 'wp_body_open', 'custom_body_open_code' );For more information read this post: https://generatewp.com/wordpress-5-2-action-that-every-theme-should-use/
// Add Google Tag code which is supposed to be placed after opening body tag. add_action( 'wp_body_open', 'wpdoc_add_custom_body_open_code' ); function wpdoc_add_custom_body_open_code() { echo '<!-- Google Tag Manager (noscript) --><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-J4LMVLR" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript><!-- End Google Tag Manager (noscript) -->'; }