Title: wp_body_open
Published: May 7, 2019
Last modified: August 20, 2026

---

# do_action( ‘wp_body_open’ )

## In this article

 * [Source](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#wp--skip-link--target)

Triggered after the opening body tag.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#source)󠁿

    ```php
    do_action( 'wp_body_open' );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/general-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/general-template.php#L3445)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/general-template.php#L3445-L3445)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_body_open()](https://developer.wordpress.org/reference/functions/wp_body_open/)`wp-includes/general-template.php` |

Fires the wp_body_open action.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#comment-content-3201)
 2.    [rabmalin](https://profiles.wordpress.org/rabmalin/)  [  7 years ago  ](https://developer.wordpress.org/reference/hooks/wp_body_open/#comment-3201)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%23comment-3201)
     Vote results for this note: 10[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%23comment-3201)
 4.      ```php
         // 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="https://www.googletagmanager.com/ns.html?id=GTM-J4LMVLR&quot; height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript><!-- End Google Tag Manager (noscript) -->';
         }
         ```
     
 5.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%3Freplytocom%3D3201%23feedback-editor-3201)
 6.   [Skip to note 6 content](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#comment-content-6073)
 7.    [Kamal Hosen](https://profiles.wordpress.org/ikamal/)  [  4 years ago  ](https://developer.wordpress.org/reference/hooks/wp_body_open/#comment-6073)
 8.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%23comment-6073)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%23comment-6073)
 9.  wp_open_body is the new way to you can add a new sticky header from anywhere you
     want
 10.     ```php
         function sticky_header_code() {
          	echo 'You can use HTML too here';
         }
         add_action( 'wp_body_open', 'sticky_header_code' );
         ```
     
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%3Freplytocom%3D6073%23feedback-editor-6073)
 12.  [Skip to note 7 content](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#comment-content-3255)
 13.   [Keramot UL Islam](https://profiles.wordpress.org/sourav926/)  [  7 years ago  ](https://developer.wordpress.org/reference/hooks/wp_body_open/#comment-3255)
 14. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%23comment-3255)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%23comment-3255)
 15. **Backward Compatibility**
      A conditional check can make it compatible with older
     WordPress versions.
 16.     ```php
         <!DOCTYPE html>
         <html <?php language_attributes(); ?>>
           <head>
         	<meta charset="<?php bloginfo( 'charset' ); ?>">
     
             <?php wp_head(); ?>
     
           </head>
     
           <body <?php body_class(); ?>>
     
         	<?php
             if ( function_exists( 'wp_body_open' ) ) {
         		wp_body_open();
         	}
         	?>
     
     
             <?php wp_footer(); ?>
     
           </body>
         </html>
         ```
     
 17. For More Information: [https://make.wordpress.org/themes/2019/03/29/addition-of-new-wp_body_open-hook/](https://make.wordpress.org/themes/2019/03/29/addition-of-new-wp_body_open-hook/)
 18.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%3Freplytocom%3D3255%23feedback-editor-3255)
 19.  [Skip to note 8 content](https://developer.wordpress.org/reference/hooks/wp_body_open/?output_format=md#comment-content-3192)
 20.   [Rami Yushuvaev](https://profiles.wordpress.org/ramiy/)  [  7 years ago  ](https://developer.wordpress.org/reference/hooks/wp_body_open/#comment-3192)
 21. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%23comment-3192)
     Vote results for this note: -4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%23comment-3192)
 22. Basic usage:
 23.     ```php
         function custom_body_open_code() {
             return '<!-- some code -->';
         }
         add_action( 'wp_body_open', 'custom_body_open_code' );
         ```
     
 24. For more information read this post: [https://generatewp.com/wordpress-5-2-action-that-every-theme-should-use/](https://generatewp.com/wordpress-5-2-action-that-every-theme-should-use/)
 25.  * returning the code won’t output anything. Echo it instead.
      * [svax](https://profiles.wordpress.org/svax/) [7 years ago](https://developer.wordpress.org/reference/hooks/wp_body_open/#comment-3482)
 26.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F%3Freplytocom%3D3192%23feedback-editor-3192)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_body_open%2F)
before being able to contribute a note or feedback.