This website uses cookies to allow us to see how the site is used. If you continue to use this site, we assume that you are okay with this. If you want to use the sites without cookies, please see our privacy policy.

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/

About

A geek who likes to code and be nice ^_^

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.