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. :)

2 Answers 2


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==============*/
    function edei_widget_class_adder($params){
    if( $params[0]['name']=='Home Widget Area' ){
        if( ($GLOBALS['my_widget_num']%4)==0 ){
            $params[0]['before_widget'] = str_replace('class="', 'class="marginAdjust ', $params[0]['before_widget']);

    return $params;

function edei_widget_counter_reset($sidebars_widgets) {
   $GLOBALS['my_widget_num'] = 1;
   return $sidebars_widgets;
  • This wont work as there's a bracket too much.
    – kaiser
    Oct 9, 2012 at 12:21

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.