-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
do_action('get_header') should occur before wp_head() #3171
Comments
This doesn't seem correct? Ref https://github.com/WordPress/WordPress/blob/master/wp-content/themes/twentytwentyone/header.php
Hooking into |
Looking at your example from TwentyTwentyOne, header.php is loaded through this call in index.php. The Haven't investigated why Gravity Forms gives this particular guidance for using that action hook. But I glanced at some other plugins, and the I get that |
It seems wrong that The Events Calendar would be hooking into While Sage doesn't follow the standard WordPress theme behavior, these plugins aren't using the correct hooks for their functionality |
I don't disagree and haven't investigated exactly why they are using that hook. Some of my Woocommerce plugins use that hook too. But I still think that the order in Sage's index.php template is wrong, and I've modified our index.php template like this, moving that action out of the body:
|
I do not agree. What This can vary from Take this quick response from ChatGPT for example - it gives the example of putting In Sage's case, we do not need to do this as everything is otherwise pretty dry as-is thus we can omit having a header template in entirety. Since we do this, for obvious compatibility reasons, we have to do I am very confident |
How the My point here is that the function Sage doesn't need a header template but does include the Even though Sage doesn't have a header template, my request is that Sage sticks to the hook definition of "Fires before the header template file is loaded" and execute it where other themes typically do, which is not after |
Look at twentytwentyone (the last theme before they changed to block templates) as an example:
In what world would you want a plugin to run a hook that adds markup to your page before the opening of your document? I get what you're saying, but this isn't getting changed in Sage. You will have to adjust this to your own needs or contact the plugin developers. |
I guess I should have been more precise in my analysis of what these plugins are doing to better explain the issue. Looking at the four examples I have on hand, Gravity Forms, The Events Calendar, Query Monitor, and Woocommerce Subscriptions, and after a cursory examination of their code, here is what I found. None of them are emitting markup on that action hook, though at first glance a couple of function names were deceptive. As you mentioned and for obvious reasons, this is not a place to emit markup. They all are looking for a code execution point immediately before I did reference twentytwentone and the sequence it follows:
In Sage, the |
That definitely makes more sense. I will look into this. |
To give a bit more context, the Gravity Forms example triggered this for me. I'm embedding a form in a template using their function call, not in a post. Because the form is not in a post, WordPress doesn't know about the form to enqueue their styles/scripts in the header because it hasn't gotten to that template code yet, so it needs to be done manually. (They only enqueue when a form is present on a post.) They instruct you to run their enqueuing function immediately before In the case of The Events Calendar, they use the Query Monitor seems to use |
Thanks a lot for providing more info on this. Sorry about the initial confusion. Can you try #3167 and see if everything works as intended with your plugins? Given your plugins make extra-use of some of these hooks, you confirming that PR works will help a ton and I can go ahead and merge it in. |
#3167 was merged but please let me know if you still experience any issues. |
Thanks. I'll be giving it a test later today and will let you know if any issues. |
Version
10.7.0
What did you expect to happen?
The default WordPress theme behavior is to load header.php using a call to
get_header()
. Sage doesn't do this but does includedo_action('get_header')
so that any plugins relying on that action (maybe to enqueue styles, scripts, or meta tags) still fire.I've embedded a Gravity Form in a theme file using their function call. For this to work, you need to manually enqueue the required styles and scripts for the page where the form is appearing.
Gravity Forms is expecting the typical WordPress ordering, where the
get_header
action runs beforewp_head()
. The result should be that their styles get enqueued inwp_head()
, before the Sage app.css.What actually happens?
Sage does fire the
get_header
action in index.php, but afterwp_head()
and after the body_open. The result for this Gravity Forms use case is that the styles don't get enqueued until the footer, which messes up the stylesheet ordering.While not difficult to work around for my use case, I'm wondering if the ordering of that action should change in index.php. If any other plugins are relying on the
get_header
action to enqueue styles, scripts, or other things that belong inwp_head()
, the current order doesn't work because it is too late. Theget_footer
action does have the proper ordering.Steps to reproduce
Use the
get_header
action to enqueue a style that should appear in the<head>
. The style will appear inwp_footer()
instead.System info
No response
Log output
No response
Please confirm this isn't a support request.
No
The text was updated successfully, but these errors were encountered: