mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Script Loader: Load block support styles in the head for block themes.
The dynamic block styles for layout and elements should be loaded in the head for block themes. While that should also be the case for classic themes, the current mechanism we use (render_block) does not allow us to do that, hence, this PR doesn't change anything for them and will be loaded the body. Props oandregal, youknowriad, wpsoul. Fixes #55148. git-svn-id: https://develop.svn.wordpress.org/trunk@52741 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1332,3 +1332,29 @@ function _wp_multiple_block_styles( $metadata ) {
|
||||
return $metadata;
|
||||
}
|
||||
add_filter( 'block_type_metadata', '_wp_multiple_block_styles' );
|
||||
|
||||
/**
|
||||
* This function takes care of adding inline styles
|
||||
* in the proper place, depending on the theme in use.
|
||||
*
|
||||
* For block themes, it's loaded in the head.
|
||||
* For classic ones, it's loaded in the body
|
||||
* because the wp_head action (and wp_enqueue_scripts)
|
||||
* happens before the render_block.
|
||||
*
|
||||
* See https://core.trac.wordpress.org/ticket/53494.
|
||||
*
|
||||
* @param string $style String containing the CSS styles to be added.
|
||||
*/
|
||||
function wp_enqueue_block_support( $style ) {
|
||||
$action_hook_name = 'wp_footer';
|
||||
if ( wp_is_block_theme() ) {
|
||||
$action_hook_name = 'wp_enqueue_scripts';
|
||||
}
|
||||
add_action(
|
||||
$action_hook_name,
|
||||
function () use ( $style ) {
|
||||
echo "<style>$style</style>\n";
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user