Support » Developing with WordPress » Action: ‘wp_enqueue_scripts’ does not output the link

  • Registering the style in a plugin should produces this output:
    <link rel=’stylesheet’ id=’bs-style-css’ href=’http://localhost:3000/wp/wp-content/plugins/bootstrap-login/css/bs-style.css?ver=20120208′ type=’text/css’ media=’all’ />

    But it does not!

    This is my code:

    add_action( 'wp_enqueue_scripts', 'wpbootstrap_css_styles' );
    
    function wpbootstrap_css_styles() {
       // Register the style for the plugin:
       wp_register_style( 'bs-style', 
    	    	      plugins_url( '/css/bs-style.css', __FILE__ ), 
    	    	      array(), '20180620', 'all' );
        wp_enqueue_style( 'bs-style' );
    }
    

    What am I doing wrong, not enough or what?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    Placing you code in my site specific plugin produces the expected output, there’s nothing wrong with your code, it’s something else. Caching in place? Minifying or optimizing code present?

    Excellent, thanks for testing.
    Where did you put the code; I put mine in the “main” file of my plugin.
    And, as I said, nothing happend.

    Moderator bcworkz

    (@bcworkz)

    Yup, same here. It’s my plugin’s only file. Naturally the CSS was not applied since the file is missing on my site, but the expected link tag was output. If none of the previously mentioned reasons do not explain things, there could be a plugin or theme conflict of some sort. If you switched to a twenty* default theme and deactivated all other plugins, your CSS file should be referenced.

    Thanks for your help.
    My bad is that I commented out wp_head() in the header.
    There is just a lot of unwanted s… in there. Is there a way to eat my cake and still have it?

    It is possible to eat my cake and still have it!

    In the dedicated header file of the plugin I put this code:

       <link href="<?php echo plugins_url( '/css/bs-style.css' ); ?>" rel="stylesheet" />
    

    which produces this output:
    <link href=”http://localhost:3000/wp/wp-content/plugins/css/bs-style.css” rel=”stylesheet”>

    Just what I want!

    Moderator bcworkz

    (@bcworkz)

    That’s fine for your own site, but it’s considered incorrect practice for plugins, especially those destined for the repository. Just sayin’. FYI: if you wanted to be proper and wp_head() is causing undesirable output, try calling apply_filters('wp_head'); instead to get enqueued stylesheets referenced. If that still causes undesirable output, you could dequeue anything hooked to the wp_head action.

    This ability to manage output through enqueue and dequeue without altering template code in largely the reason for enqueuing CSS (and scripts as well). It also allows us and WP to manage in what order things are referenced, sometimes very important.

    Anyway, I’m glad you found a solution that works for you.

    Great! That points me to the direction.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.