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.

is there any Way to Catch Last widget box or div from same widget area?? i mean i have 4 widgets in footer widget area but due to design issue my 3rd widget box style+width is different.so i want to add extra class to 3rd box container using php.is there any way to do that? please reply.

Thanks in advance. :)

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Add the following code in your functions.php file of the theme directory. Replace widget name "Home Widget Area" with your widget's name

    /*=============WIDGETs CSS CLASS CONTROLLER==============*/
    $GLOBALS['my_widget_num']=1;
    function edei_widget_class_adder($params){
    if( $params[0]['name']=='Home Widget Area' ){
        $GLOBALS['my_widget_num']++;
        if( ($GLOBALS['my_widget_num']%4)==0 ){
            $params[0]['before_widget'] = str_replace('class="', 'class="marginAdjust ', $params[0]['before_widget']);
        }
    }

    //print_r($params);
    return $params;
}
add_filter('dynamic_sidebar_params','edei_widget_class_adder');

function edei_widget_counter_reset($sidebars_widgets) {
   $GLOBALS['my_widget_num'] = 1;
   return $sidebars_widgets;
}
add_filter('sidebars_widgets','edei_widget_counter_reset');
share|improve this answer
    
This wont work as there's a bracket too much. –  kaiser Oct 9 '12 at 12:21
add comment

Usually in Worpdress every widget has a unique id of the form "widget_type-xx" where widget_type is the widget internal name, and xx is a progressive number. I think you may use that id to apply custom css rules, and you don't really need to add a class via php, unless that widget will be replaced in future (the id would change in that case).

share|improve this answer
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.