Add Code After the Body Tag in WordPress

WordPress 5.2 introduces a new function called wp_body_open(). This function triggers wp_body_open action and useful to place code after the opening of the body element.

add_action('wp_body_open', 'body_scripts');
function body_scripts() {
    ?>
	<script>console.log('test here');</script>
	<?php
}

Leave a Reply

Your email address will not be published. Required fields are marked *