The code below is part of a widget that goes with my theme. I'm trying to include a stylesheet that the widget needs by placing an add_action call to wp_head. However, the function never fires in this context.
What am I missing?
function widget( $args, $instance ) {
if(!get_option('my_slider')) return;
add_action('wp_head', 'my_sliderCSS');
extract($args);
$title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance );
$text = apply_filters( 'widget_text', $instance['text'], $instance );
$hide_title = isset( $instance['hide_title'] ) ? $instance['hide_title'] : false;
echo $before_widget;
if ( $title && !$hide_title )echo $before_title . $title . $after_title;
if ( $text )?><div id="slider"><dl><?php echo $instance['filter'] ? wpautop($text) : $text; ?></dl></div>
<?php echo $after_widget;
}
my_sliderCSS
does not fire? I'm afraid thatwp_head
has long fired off before yourwidget()
(choice of name may collide with something else, careful) is called, place youradd_action
code inside your widget initialization.