Addition of new ‘wp_body_open’ hook.

Starting from WordPress 5.2 a new function is added – wp_body_open() – that is used to trigger a wp_body_open action. The intention of this action is to allow people to add things – like a <script> tag – directly inside the body of a page.

Themes should start adding this hook to their themes as soon as 5.2 releases. The function should be placed inside of the <body> tag immediately after it is opened like so:

<body <?php body_class(); ?>>
<?php wp_body_open(); ?>

See also the notes at the end of this post and what Justin says in his comment for alternative acceptable ways to add the new hook to your theme.

Use of this hook is a pluginPlugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party-territory item so themes are unlikely to be doing anything other than adding the tag to the template in the correct spot.

Bear in mind that using this hook should be reserved for output of unseen elements like <script> tags or additional metadata. It should not be used to add arbitrary HTMLHTML HTML is an acronym for Hyper Text Markup Language. It is a markup language that is used in the development of web pages and websites. content to a page that could (and probably would) break layouts or lead to unexpected situations.

Backwards Compatibility

UPDATE: see this comment for an alternative: https://make.wordpress.org/themes/2019/03/29/addition-of-new-wp_body_open-hook/#comment-43714

Additionally for backwards compatibility it is recommended you use a shim to add support on old WP versions and prevent your theme throwing a fatal error for undefined function use. The shim that is suggested looks like this:

<?php
if ( ! function_exists( 'wp_body_open' ) ) {
        function wp_body_open() {
                do_action( 'wp_body_open' );
        }
}

It has also been pointed out that you could call the do_action directly where the wp_body_open() function is placed in my first example (and where it is in the coreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. themes). This removes any need for backwards compatibility code. My personal suggestion is to use the function + shim method because that is how core looks to be handling it – however calling do_action directly would also be fine.