Make WordPress Core

Opened 20 months ago

Last modified 19 months ago

#57267 new defect (bug)

wp_enqueue_style is not working under shortcode

Reported by: hasanrang05's profile hasanrang05 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.1.1
Component: Shortcodes Keywords: reporter-feedback
Focuses: css Cc:


we have tested in older version wp_enqueue_style('some-id'); is working fine on 5.7.8

but it's not working on 6.1.1
even its not working on "wp_head", "wp_footer"

Change History (1)

#1 @costdev
19 months ago

  • Component changed from General to Shortcodes
  • Keywords reporter-feedback added

Hi @hasanrang05, welcome to Trac!

I have tried the following:

  1. Insert a Shortcode block and enter the following shortcode: [my_shortcode].
  1. Create the following stylesheet wp-content/plugins/test_57267/css/my-shortcode.css:
    .my_shortcode { color: red; }
  1. Create the following plugin file: wp-content/plugins/test_57267/test_57267.php.
  2. Test 1 - Add this to the file and activate the plugin:
     * Plugin Name: Enqueue a style in a shortcode.
    add_action( 'init', 'register_style_57267' );
    function register_style_57267() {
            wp_register_style( 'my_shortcode_styles', plugins_url( 'css/my-shortcode.css', __FILE__ ) );
    add_shortcode( 'my_shortcode', 'my_shortcode_callback' );
    function my_shortcode_callback() {
            wp_enqueue_style( 'my_shortcode_styles' );
            return '<p class="my_shortcode">Hello</p>';
  1. Load the post on the frontend. You should see Hello.
  1. Test 2 - Change the contents of the plugin file above to:
     * Plugin Name: Enqueue a style in a shortcode.
    add_shortcode( 'my_shortcode', 'my_shortcode_callback' );
    function my_shortcode_callback() {
                    plugins_url( 'css/my-shortcode.css', __FILE__ )
            return '<p class="my_shortcode">Hello</p>';
  1. Refresh the page on the frontend. You should still see Hello.

In both cases, I saw Hello on the frontend.

Can you provide more detail about what's not working? Could it be a plugin/theme conflict occurring?

Note: See TracTickets for help on using tickets.