Last active
March 22, 2019 23:30
-
-
Save raazon/544d7c27248674c2d74091c03ba0db71 to your computer and use it in GitHub Desktop.
Adding a div to wrap widget content after the widget title ( wrap widget content )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* If no title given then add widget-content wrapper to before_widget | |
* If title given then add content wrapper to before_widget | |
*/ | |
add_filter('dynamic_sidebar_params', 'check_widget_template'); | |
function check_widget_template($params){ | |
global $wp_registered_widgets; | |
$settings_obj = $wp_registered_widgets[$params[0]['widget_id']]['callback'][0]; | |
$the_settings = $settings_obj->get_settings(); | |
$the_settings = $the_settings[$params[1]['number']]; | |
if( ! isset($the_settings['title']) && empty($the_settings['title']) ){ | |
$params[0]['before_widget'] .= '<div class="content">'; // if no title given | |
$params[0]['after_widget'] .= '</div>'; // if no title given | |
}else{ | |
$params[0]['after_widget'] .= '</div>'; // if title given | |
$params[0]['after_title'] .= '<div class="content">'; // if title given | |
} | |
return $params; | |
} | |
/** | |
* Add class to number 3 widget [ THIS IS NOT PART OF 'wrap widget content' ] | |
*/ | |
add_filter('dynamic_sidebar_params', 'footer_widgets'); | |
function footer_widgets($params){ | |
global $appr_widget_num; //Our widget counter variable | |
//Check if we are displaying "Footer Sidebar" | |
if (isset($params[0]['id']) && $params[0]['id'] == 'app-1') { | |
$footappr_widget_numer_widget_num++; | |
$divider = 3; //This is number of widgets that should fit in one row | |
//If it's third widget, add last class to it | |
if ($appr_widget_num % $divider == 0) { | |
$class = 'class="last '; | |
$params[0]['before_widget'] = str_replace('class="', $class, $params[0]['before_widget']); | |
} | |
} | |
return $params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment