1

I did see the other topic similar to this but I cannot get mine to work.

I am using WordPress 3.8 and am creating a custom widget for a site. I need to style it a certain way so I need to load an external stylesheet.

I have tried:

function widget($args, $instance)
  {
    wp_enqueue_style( 'gamestats-style', plugins_url('css/styles.css', __FILE__) ); 

    //Widget content
  }

with no luck. I have the css file located in the css directory of my plugin directory "game-stats" so i believe the url is correct.

plugins/game-stats/css/styles.css

if I embed the styles in the php by way of <script>....styles...</script> it works fine but this is really bad practice. What am I doing wrong?

Any help would be greatly appreciated.

  • Please check if the path to the file is correct. You can use tools like FireBug to determine the specified path... – Sven Jan 5 '14 at 0:44
0

Please check this reference is_active_widget, check the example for an exact solution. That code will go within the __construct() method right after parent::__construct() is called. wp_enqueue_style works if it is called before wp_head is called. and widget() method are called definitely after wp_head is loaded as it just display the HTML template.

So here is an example of loading scripts for widget.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.