Action hook after opening body tag
Before WordPress 5.2.0 it was always a hassle to add anything just after the opening HTML body tag in your theme. For the release of 5.2.0 came the action hook “wp_body_open”. This was added to core and of course, your theme or any themes for this release need to be compatible with core but we’ll come to that bit later, first let’s look at what can be done with the action hook.
// Add your code after opening body tag.
add_action( 'wp_body_open', 'wpstx_add_after_opening_body_tag' );
function wpstx_add_after_opening_body_tag() {
echo '<!-- added your code here en -->';
}
For backward compatibility you should add this to your theme immediately after your opening body tag. If you are using a premium theme ask the theme developer to add this if it doesn’t already exist
<?php
if ( function_exists( 'wp_body_open' ) ) {
wp_body_open();
}
?>
@source https://developer.wordpress.org/reference/functions/wp_body_open/