[resolved] Alternating Sidebar Widget Styles (4 posts)

  1. eryanv
    Posted 6 years ago #

    I'd like my sidebar widgets to alternate between two styles, much like you might have two styles for table rows (one for even numbered rows, and one for odd numbered rows). Can this be done with the dynamic sidebars? If so, how?

  2. alanft
    Posted 6 years ago #

    you CAN do this with my widget logic plugin


    using the widget_content filter capability. and this in your functions.php:

    add_filter('widget_content', 'make_alternating_widget_styles');
    function make_alternating_widget_styles($content='')
    { global $make_alt_ws;
    return preg_replace('/(class="widget )/', "$1 widget_${make_alt_ws} ", $content);

    so if your widgets are usually class="widget ..." this will add in "widget_style_a"/"widget_style_b" into that class definition.

  3. eryanv
    Posted 6 years ago #

    I was hoping something would be built into core, but this works too.


  4. jacMadsen
    Posted 6 years ago #

    Having it in the functions.php file is a much better option as it won't be saved over when the core is updated.

Topic Closed

This topic has been closed to new replies.

About this Topic