Opened 4 years ago
Closed 4 years ago
#47032 closed enhancement (wontfix)
Rename wp_body_open hook and function
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.2 |
Component: | Themes | Keywords: | |
Focuses: | template | Cc: |
Description
The wp_body_open
hook is added to v5.2 in this ticket #12563. However, I think the naming is bad. The hook doesn't fit the context where the body tag opens. It happens when the body tag already opened. We can tell in another way: we don't know that hook fires before or after the tag is opened by just looking into its name.
I suggest using the naming convention in the Theme Hook Alliance:
- Hooks should be of the form
prefix_ + [section of the theme] + _[placement within block]
. - Hooks should be named based upon the generally-accepted semantic name for the section of a theme they cover, e.g.,
prefix_content_*
should refer to the section/block of a theme containing the content (or "The Loop"), whileprefix_sidebar_*
would refer to the sidebars generally called byget_sidebar()
. - Hooks should be suffixed based upon their placement within a block.
- Hooks immediately preceding a block should use
_before
. - Hooks immediately following a block should use
_after
. - Hooks placed at the very beginning of a block should use
_top
. - Hooks placed at the very end of a block should use
_bottom
.
- Hooks immediately preceding a block should use
- If the theme section covered by a hook can contain multiple semantic elements, it should be pluralized. (Primarily applies to
prefix_sidebars_before/after
in the early goings.)
In this case, the prefix is wp_
, the block is body
, so the hook should be wp_body_top
.
Benefit: this provides a consistent naming conversion for future hooks that implemented in the themes by WordPress or by theme providers.
Change History (4)
#1
@
4 years ago
- Keywords dev-feedback 2nd-opinion needs-dev-note removed
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
#2
@
4 years ago
Thanks for your comment, @pento!
The WordPress hooks with post_
or pre_
unlikely match this context. They're used for internal actions, like before or after doing something. While in the front end, there's exclusively and clearly a context (HTML block). The hook tells more about the location than action. That's why the words *_before
, *_after
, *_top
, *_bottom
make sense.
Also, this is the first hook in the front end for themes (except required wp_head
and wp_footer
), it will create a kind of standard for future hooks. I'm thinking about the hooks for content areas in Gutenberg Phase 2.
For those reasons, I think it's a good time to start a naming convention now.
Thank you for the suggestion, @rilwis!
The THA link is interesting, but doesn't seem to have gained much traction since its proposal.
There are quite a few different naming forms that are scattered throughout the WordPress codebase. The
*_top
form of hook name appears, as doespost_*_tag
,*_tag
,*_tag_pre
,pre_*
... you get the idea. 🙂Outside of a substantial re-architecture of our hook naming scheme, I don't think it's necessary to try and lock into a particular format for new hooks.