Created
October 15, 2016 15:33
-
-
Save amin3d/e90357f73df5f61d1a6a3e98030cb2d3 to your computer and use it in GitHub Desktop.
Register widget with wrapping the widget content
This file contains hidden or 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
function pana_widgets_init() { | |
register_sidebar( array( | |
'name' => 'سایدبار پست', | |
'id' => 'post_sidebar', | |
'description' => 'در این سایدبار می توایند به تعداد دلخواه ابزارک قرار دهید', | |
'before_widget' => '<section id="%1$s" class="widget %2$s">', | |
'after_widget' => '</div></section>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2><div class="widget-content">', | |
) ); | |
} | |
add_action( 'widgets_init', 'pana_widgets_init' ); | |
// if no title then add widget content wrapper to before widget | |
add_filter( 'dynamic_sidebar_params', 'check_sidebar_params' ); | |
function check_sidebar_params( $params ) { | |
global $wp_registered_widgets; | |
$settings_getter = $wp_registered_widgets[ $params[0]['widget_id'] ]['callback'][0]; | |
$settings = $settings_getter->get_settings(); | |
$settings = $settings[ $params[1]['number'] ]; | |
if ( $params[0][ 'after_widget' ] == '</div></section>' && isset( $settings[ 'title' ] ) && empty( $settings[ 'title' ] ) ) | |
$params[0][ 'before_widget' ] .= '<div class="widget-content">'; | |
return $params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment