Search code examples
phpwordpressactioncustomization

Insert HTML after opening <body> tag in WordPress's admin pages


I am adding a WordPress network to an existing website and one of my requirements is to embed the admin utility within our existing sites' layout.

I've written a custom plugin that registers functions to the admin_head and admin_footer actions. admin_head inserts content inside the <head> tag and admin_footer inserts content near the end of the <body> section.

Is there another action that inserts content immediately after the <body> tag or just before any visible HTML is output by WordPress?

Thanks!


Solution

  • Wordpress 5.2.0 introduced the wp_body_open hook (detailed in the WordPress codex)

    // Add code after opening body tag.
    add_action( 'wp_body_open', 'wpdoc_add_custom_body_open_code' );
     
    function wpdoc_add_custom_body_open_code() {
        echo '<!-- custom code -->';
    }