[wp-hackers] Widget custom CSS

John Blackbourn johnbillion+wp at gmail.com
Wed Nov 3 10:20:35 UTC 2010


You could go with the wrapper class method. Instead of loading a CSS
file conditionally based on which option is chosen, change the widget
class name based on which option is chosen. Then you can define all
the different styles in one CSS file which is always loaded. Eg:

When option 1 is chosen the widget gets a class name of my_widget_layout_1:

<div class="my_widget_layout_1">
<p>Foo bar</p>
</div>

When option 2 is chosen the widget gets a class name of my_widget_layout_2:

<div class="my_widget_layout_2">
<p>Foo bar</p>
</div>

These will be styled thus in your CSS file:

.my_widget_layout_1 {
color: red;
}

.my_widget_layout_2 {
color:blue;
}

Hope this helps.

John

On Wed, Nov 3, 2010 at 2:57 AM, Jeff Rose <mirepup at gmail.com> wrote:
>> Use wp_enqueue_style(), change the handle to whatever optional stylesheet
>> the user has chosen.
>> http://codex.wordpress.org/Function_Reference/wp_enqueue_style
>>
>> Yep, I thought of that, but how does the page know what option the widget
> has set in it? That would be happening before the widget is loaded.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list