Change widget heading from custom sidebars

Hi, I need to change not the Main Sidebar widget headings like in the post here, but the Custom Sidebar widget headings from h4 to div.

Is there a way to change the heading for all custom sidebars or do I have to change it for each unique ups-sidebar-id?

Can you please help me out with some code?

This would be greatly appreciated.

greetz

Hi @agepilar,

Currently, it’s possible to change it via child theme. You need to edit this file in the parent theme:

x/framework/functions/custom-sidebars.php around line 365-366.

Hope it helps :slight_smile:

Hi @thai,

i edited the file

x/framework/functions/custom-sidebars.php

function ups_sidebars_validate( $input ) {

  if ( isset( $input['add_sidebar'] ) ) {

    $sidebars = get_option( 'ups_sidebars' );

    if ( ! empty( $input['add_sidebar'] ) ) {
      $sidebar_id_slug = 'ups-sidebar-' . sanitize_title_with_dashes( remove_accents( $input['add_sidebar'] ) );
      $sidebars[$sidebar_id_slug] = array(
        'name'          => esc_html( $input['add_sidebar'] ),
        'description'   => '',
        'sidebar-id'    => $sidebar_id_slug,
        'before_title'  => '<div class="h-widget">',
        'after_title'   => '</div>',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'pages'         => array(),
        'taxonomies'    => array(),
        'children'      => 'off',
        'index-blog'    => 'off',
        'index-shop'    => 'off'
      );
    }

and tried it both way. First copy the file via ftp in the pro/framework/functions/ folder and after that didnt work in the child themes folder pro-child/framework/functions/. Also i edited the code around line 219-228. I did clear the cache just in case. Both ways no change.

Hello @agepilar,

The modifications of the file will not work. Please use this PHP code in your child theme’s functions.php file instead:

function x_widgets_init() {

    register_sidebar( array(
      'name'          => __( 'Main Sidebar', '__x__' ),
      'id'            => 'sidebar-main',
      'description'   => __( 'Appears on posts and pages that include the sidebar.', '__x__' ),
      'before_widget' => '<div id="%1$s" class="widget %2$s">',
      'after_widget'  => '</div>',
      'before_title'  => '<h3 class="h-widget">',
      'after_title'   => '</h3>',
    ) );

}
add_action( 'widgets_init', 'x_widgets_init' );

Of course, please do not forget to change elements that you want to use.

like: (for each custom sidebar?)

function x_widgets_init() {

    register_sidebar( array(
      'name'          => __( 'Custom Name', '__x__' ),
      'id'            => 'ups-sidebar-custom-sb1',
      'description'   => __( 'custom-sb', '__x__' ),
      'before_widget' => '<div id="%1$s" class="widget %2$s">',
      'after_widget'  => '</div>',
      'before_title'  => '<div class="h-widget">',
      'after_title'   => '</div>',
    ) );

}
add_action( 'widgets_init', 'x_widgets_init' );

unfortunately doesn`t work

Hi @agepilar,

Nope, that’s not possible for custom sidebars. Instead, please add this code and this should apply to all sidebars.

add_filter( 'dynamic_sidebar_params', 'no_widget_title', 20 );
function no_widget_title( $params ) {
        
        $params[0]['before_title'] = '<div class="h-widget">';
        $params[0]['after_title'] = '</div>';
        
        return $params;
        
}

Hope this helps.

1 Like

Here we go, nice! Thank you for helping me out @Rad

You’re welcome. Glad we’re able to help.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.