0

First hope you will take a look example widget http://pastebin.com/2cL7BmgF

There have male and female option. Let say I select male and I want add male.css to wp_head

When I put something like this into the code it's not working.

add_action('wp_head','load_face');
function load_face() {
  wp_enqueue_style('style', WP_PLUGIN_URL . '/sample/'.$sex.'.css', null, null, 'screen');
}

Let me know what is the correct code to archive my goal. :)

1 Answer 1

3

when calling a function within a class you need to use $this

prefixadd_action('wp_head',array(&$this,'load_face'));

and you will need to populate the value of $sex

public function load_face($instance) {
  $sex = $instance['sex'];
  wp_enqueue_style('style', WP_PLUGIN_URL . '/sample/'.$sex.'.css', null, null, 'screen');
}
3
  • Thanks mate for the explanation but I'm really blur.. grgrgr. I got this Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object Question, actually.. where should I put the code into current plugin?
    – wow
    Commented Feb 23, 2011 at 9:02
  • inside the widget class
    – Bainternet
    Commented Feb 23, 2011 at 9:25
  • I'm still in the dark.
    – wow
    Commented Feb 23, 2011 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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