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 plugin-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 HTML 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:

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:

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 core 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.