Global styles: specify priority in remove_action#43073
Merged
Conversation
Mamaduka
reviewed
Aug 9, 2022
|
|
||
| remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); | ||
| remove_action( 'wp_footer', 'wp_enqueue_global_styles' ); | ||
| remove_action( 'wp_footer', 'wp_enqueue_global_styles', has_action( 'wp_footer', 'wp_enqueue_global_styles' ) ); |
Member
Author
There was a problem hiding this comment.
For sure, I tested with 1 and it works.
My reasoning was that has_action gives us the right answer all the time.
Is it bad practice or slow to query it?
Member
There was a problem hiding this comment.
It was mostly a nitpick. I don't think I've seen has_action used this way, maybe only if priority is dynamically generated, and that's a bad idea for different reasons :)
Hardcoding the value should make scanning and getting all the data you need more accessible, IMO.
This was referenced Aug 26, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
This PR sets a priority in
remove_action( 'wp_footer', 'wp_enqueue_global_styles' );, so that the core action is removed in time and the callback does not execute.Why?
In classic themes, when wp_should_load_separate_core_block_assets() returns
true, global styles are printed twice:How?
Using has_action to get the priority of the already-registered callbackHardcoding the priority to
1Testing Instructions
Switch to a classic theme.
Add the following filter somewhere:
Check that the styles in
global-styles-inline-cssare not loaded twice.