[wp-hackers] Widget custom CSS

Chris Jean gaarai at gaarai.com
Wed Nov 3 18:26:13 UTC 2010


Rather than having different stylesheet, why not have a single 
stylesheet with different each style represented by a specific class? 
Then all you have to do is output the class for the selected style in 
the main widget wrapper div or one that is inside the main widget wrapper.

The stylesheet could contain the following:

.blue p { color: #00F; }
.red p { color: #F00; }
...

Then the widget HTML could look like the following:

<?php echo $before_widget; ?>
<div class="<?php echo $widget['style']; ?>">
<?php if ( ! empty( $widget['title'] ) ) echo $before_title . 
$widget['title'] . $after_title; ?>
...

Chris Jean (AKA gaarai&  chrisbliss18)
Coder for http://ithemes.com/
http://gaarai.com/
@chrisjean


On 11/02/2010 03:12 PM, Jeff Rose wrote:
> Just curious if this is even possible:
>
> I have a widget that I'd like to allow the user to choose customization in.
> This would require loading a different CSS depending on which set of
> customizations they choose. There are 6 or 8 possible options.
>
> How can I load ONLY the correct CSS chosen by the user? Would this be better
> set in the plugin options so I can load it from there? Can a widget do
> enqueue_styles properly?
>


More information about the wp-hackers mailing list