wp_body_open()

Fire the wp_body_open action.


Description Description

See ‘wp_body_open’.


Top ↑

Source Source

File: wp-includes/general-template.php

function wp_body_open() {
	/**
	 * Triggered after the opening body tag.
	 *
	 * @since 5.2.0
	 */
	do_action( 'wp_body_open' );
}


Top ↑

Changelog Changelog

Changelog
Version Description
5.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Rami Yushuvaev

    WordPress theme developers should use `wp_head()`, `wp_body_open()` and `wp_footer()` functions in their themes (read this for more information).

    The new WordPress theme structure:

    <html>
      <head>
    
        ..
        ..
    
        <?php wp_head(); ?>
    
      </head>
      <body>
    
        <?php wp_body_open(); ?>
    
        ..
        ..
    
        <?php wp_footer(); ?>
    
      </body>
    </html>
  2. Skip to note 3 content
    Contributed by Mehedi Hasan

    I Think This is the best way for add wp_body_open(); function for backwards compatibility

    Step 1 : Checked if function is exits, if not exits then make a function called wp_body_open();

    Example:

    if ( ! function_exists( 'wp_body_open' ) ) {
        function wp_body_open() {
            do_action( 'wp_body_open' );
        }
    }

    Then put the function after the body tag.

    Example:

    <html>
      <head>
     
        ..
        ..
     
        <?php wp_head(); ?>
     
      </head>
      <body>
     
        <?php wp_body_open(); ?>
     
        ..
        ..
     
        <?php wp_footer(); ?>
     
      </body>
    </html>
  3. Skip to note 4 content
    Contributed by Ahir Hemant

    Custom Theme Hooks

    Many themes use their own custom actions at the beginning of body tag. They should consider migrating to the core wp_body_open action.

    For backwards compatibility, when injecting custom code, theme developers can use conditional logic to hook to the right action

    function custom_code() {
        return '<!-- some code -->';
    }
    
    if ( did_action( 'wp_body_open' ) ) {
        add_action( 'wp_body_open', 'custom_code' );
    } else {
        add_action( 'custom_theme_hook', 'custom_code' );
    }

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