do_action( ‘wp_body_open’ )

Triggered after the opening body tag.


do_action( 'wp_body_open' );



User Contributed Notes

  1. Skip to note 5 content
    // Add Google Tag code which is supposed to be placed after opening body tag.
    add_action( 'wp_body_open', 'wpdoc_add_custom_body_open_code' );
    function wpdoc_add_custom_body_open_code() {
    	echo '<!-- Google Tag Manager (noscript) --><noscript><iframe src="; height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript><!-- End Google Tag Manager (noscript) -->';
  2. Skip to note 6 content

    Backward Compatibility
    A conditional check can make it compatible with older WordPress versions.

    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    	<meta charset="<?php bloginfo( 'charset' ); ?>">
        <?php wp_head(); ?>
      <body <?php body_class(); ?>>
        if ( function_exists( 'wp_body_open' ) ) {
        <?php wp_footer(); ?>

    For More Information:

  3. Skip to note 8 content

    Basic usage:

    function custom_body_open_code() {
        return '<!-- some code -->';
    add_action( 'wp_body_open', 'custom_body_open_code' );

    For more information read this post:

You must log in before being able to contribute a note or feedback.