File: /mnt/data/dreamssalon-wp-market/wp-content/themes/dreamsalon/inc/register_widget.php
<?php
/* Register Menu */
add_action( 'init', 'dreamsalon_register_menus' );
function dreamsalon_register_menus() {
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu','dreamsalon' )
) );
}
function dreamsalon_second_widgets_init() {
$args_blog = array(
'name' => esc_html__( 'Blog Sidebar' ,'dreamsalon'),
'id' => 'blog-sidebar',
'description' => esc_html__( 'Main Sidebar','dreamsalon' ),
'class' => '',
'before_widget' => '<div id="%1$s" class="widget card %2$s">',
'after_widget' => '</div></div>',
'before_title' => '<div class="card-header mb-0"><h4 class="sidebar-widget-title mb-0">',
'after_title' => '</h4></div><div class="card-body">',
);
register_sidebar( $args_blog );
}
add_action( 'widgets_init', 'dreamsalon_second_widgets_init' );
/**
* Fallback for widgets that have no title: add the .widget-inner wrapper
*/
add_filter( 'dynamic_sidebar_params', 'dreamsalon_widget_inner_fallback' );
function dreamsalon_widget_inner_fallback( $params ) {
// target only our sidebar
if ( isset( $params[0]['id'] ) && 'blog-sidebar' === $params[0]['id'] ) {
// if the before_widget already contains widget-inner, do nothing
if ( false === strpos( $params[0]['before_widget'], 'widget-inner' ) ) {
/*
* Widgets without titles won't print 'after_title' so our opening <div class="widget-inner">
* never appears. Append it to before_widget as a fallback and ensure after_widget closes it.
*/
$params[0]['before_widget'] .= '<div class="card-body">';
// ensure we still close both inner + outer
$params[0]['after_widget'] = '</div></div>';
}
}
return $params;
}