Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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. :)

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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');
}
share|improve this answer
    
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 Feb 23 '11 at 9:02
    
inside the widget class –  Bainternet Feb 23 '11 at 9:25
    
I'm still in the dark. –  wow Feb 23 '11 at 11:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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