Make WordPress Core

Opened 21 months ago

Last modified 10 months ago

#56993 new feature request

I want to put a filter in the wp_enqueue_block_support_styles function.

Reported by: nendeb55's profile nendeb55 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.1
Component: Script Loader Keywords:
Focuses: Cc:

Description (last modified by sabernhardt)

In the wp_enqueue_block_support_styles function, I'm changing the $action_hook_name to header or footer for block theme and classic theme.
In that case, when using PHP templates in a customized scene with a block theme, the CSS may not be output if it is a header.
(If it is a footer, it will be output.)

So I would like to put a filter in the wp_enqueue_block_support_styles function so that $action_hook_name can be changed freely

https://developer.wordpress.org/reference/functions/wp_enqueue_block_support_styles/

Change History (2)

#1 @nendeb55
21 months ago

For example.

<?php
function wp_enqueue_block_support_styles( $style, $priority = 10 ) {
        $action_hook_name = 'wp_footer';
        if ( wp_is_block_theme() ) {
                $action_hook_name = 'wp_head';
        }

        //Add Filter
        $action_hook_name = apply_filters( 'wp_enqueue_block_support_styles_action_hook_name', $action_hook_name );

        add_action(
                $action_hook_name,
                static function () use ( $style ) {
                        echo "<style>$style</style>\n";
                },
                $priority
        );
}

#2 @sabernhardt
10 months ago

  • Component changed from General to Script Loader
  • Description modified (diff)
Note: See TracTickets for help on using tickets.