WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 12 months ago

#48887 new enhancement

New action hooks: admin_body_open, login_body_open & embed_body_open

Reported by: ramiy Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch
Focuses: administration, template Cc:

Description

Background

In changeset 45042 WordPress 5.2 finally introduced the long waited wp_body_open() function which fires the wp_body_open action hook immediately after the opening body tag.

This little action helps developers to insert JavaScript right after the opening body tag required by 3rd party services like Google Tag Manager.

Dev note: https://make.wordpress.org/core/2019/04/24/miscellaneous-developer-updates-in-5-2/

We did a very good job but the hooks are not consistent on other pages (dashboard, login pages and embed templates). This will allow developers to insert code not only to the theme.

Theme Structure

The new theme structure uses several basic functions which fires action hooks:

  • wp_head action fired by wp_head()
  • wp_footer action fired by wp_footer()
  • wp_body_open action fired by wp_body_open()

But the front end is not the only place where developers need to insert JavaScript.

WP Admin

The WordPress dashboard uses the following action hooks:

  • admin_head action
  • admin_footer action

Missing admin_body_open action.

Login Page

The login page uses the following action hooks:

  • login_head action
  • login_footer action

Missing login_body_open action.

Embed Templates

The embed templates uses the following action hooks:

  • embed_head action
  • embed_footer action

Missing embed_body_open action.

Other

The attached patch added the missing {$page}_body_open hooks.

If you know about other pages that missed, please comment bellow and I'll update the patch.

Attachments (2)

48887.patch (1.9 KB) - added by ramiy 12 months ago.
48887.2.patch (2.0 KB) - added by ramiy 12 months ago.
fix wrong location in wp-admin/admin-header.php

Download all attachments as: .zip

Change History (4)

@ramiy
12 months ago

@ramiy
12 months ago

fix wrong location in wp-admin/admin-header.php

#1 @ramiy
12 months ago

  • Summary changed from Consistent use of wp_body_open() and body opening actions to New action hooks: admin_body_open, login_body_open & embed_body_open

#2 @aaron13100
12 months ago

Hello. I feel like a hook named "wp_body_open" should be called whenever there's a <body> tag (on every page). There's a body tag on the login screen, registration screen, etc. Otherwise it could have been named "wp_front_end_body_open" or something.

cheers

Note: See TracTickets for help on using tickets.