wp_enqueue_style Does Not Behave As Documented

I have the following written in a driver:

 add_action( 'wp_enqueue_scripts', 'add_css_file' );
 function add_css_file()
 {
      // Tried this prior:
      // $path = ABSPATH . "/wp-content/plugins/this_plugin/css/";
      // wp_register_style( 'css_file', $path.'css_file.css' );

      wp_register_style( 'css_file', 'http://subdomain.mysite.com/wp-content/plugins/this_plugin/css/css_file.css' );
      wp_enqueue_style( 'css_file' );
 }

The string “css_file” does not appear in the View Source HTML and the CSS rules defined therein do not take effect.

Related posts

Leave a Reply

3 comments

  1. The problem for me lay in the fact that I am modifying the Admin screen rather than the display of a Page or Post to viewers.

    Replace:

     wp_enqueue_script(...)
    

    With:

     admin_enqueue_script(...)
    

    Best of luck.

  2. I have just tried this snippet in my site, and it is working properly. You may get conflict with some other plugin/code.

    Also make sure you don’t have any Cache enabled, and if so, try to clean up the cache. Also try to clean out your browser cache.

    Finally, if non of the above works for you, try to de-activate your plugins, one by one in order to see if some of the plugins conflicts with this function, and in last step try to change theme, also to make sure the current theme doesn’t conflict with this function.