WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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==============*/
    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;
share|improve this answer
This wont work as there's a bracket too much. – kaiser Oct 9 '12 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).

share|improve this answer

Your Answer


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.