1

I'm trying to modify a widget title in a child theme from H2 to H1. I copied the sidebar function from the parent theme's functions.php file to the child theme's function.php file according to the instructions in this thread. This is the code I placed in my child theme's functions.php file:

remove_action('widgets_init', 'codilight_lite_widgets_init');

//Register your own hook.
add_action('widgets_init', 'my_widgets_init');

function my_widgets_init() {
register_sidebar( array(
    'name'          => esc_html__( 'Default Sidebar', 'codilight-lite' ),
    'id'            => 'sidebar-1',
    'description'   => '',
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h2 class="widget-title"><span>',
    'after_title'   => '</span></h2>',
) );

// Homepage Template
register_sidebar( array(
    'name'          => esc_html__( 'Home 1', 'codilight-lite' ),
    'id'            => 'home-1',
    'description'   => '',
    'before_widget' => '<aside id="%1$s" class="home-widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h2 class="widget-title"><span>',
    'after_title'   => '</span></h2>',
) );
register_sidebar( array(
    'name'          => esc_html__( 'Home 2', 'codilight-lite' ),
    'id'            => 'home-2',
    'description'   => '',
    'before_widget' => '<aside id="%1$s" class="home-widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h2 class="widget-title"><span>',
    'after_title'   => '</span></h2>',
) );
register_sidebar( array(
    'name'          => esc_html__( 'Home 3', 'codilight-lite' ),
    'id'            => 'home-3',
    'description'   => '',
    'before_widget' => '<aside id="%1$s" class="home-widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h2 class="widget-title"><span>',
    'after_title'   => '</span></h2>',
) );
register_sidebar( array(
    'name'          => esc_html__( 'Home 4', 'codilight-lite' ),
    'id'            => 'home-4',
    'description'   => '',
    'before_widget' => '<aside id="%1$s" class="home-widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h1 class="widget-title"><span>',
    'after_title'   => '</span></h1>',
) );

}

The widget I'm trying to modify is the last one in the list, i.e, the Home 4 widget. This code is not producing any errors, it's just not working.

1 Answer 1

0

Looks like I've found the answer here. Here's the working version of the code I'm using in my child theme's functions.php file.

function my_widgets_init() {
register_sidebar( array(
    'name'          => esc_html__( 'Default Sidebar', 'codilight-lite' ),
    'id'            => 'sidebar-1',
    'description'   => '',
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h2 class="widget-title"><span>',
    'after_title'   => '</span></h2>',
) );

// Homepage Template
register_sidebar( array(
    'name'          => esc_html__( 'Home 1', 'codilight-lite' ),
    'id'            => 'home-1',
    'description'   => '',
    'before_widget' => '<aside id="%1$s" class="home-widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h2 class="widget-title"><span>',
    'after_title'   => '</span></h2>',
) );
register_sidebar( array(
    'name'          => esc_html__( 'Home 2', 'codilight-lite' ),
    'id'            => 'home-2',
    'description'   => '',
    'before_widget' => '<aside id="%1$s" class="home-widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h2 class="widget-title"><span>',
    'after_title'   => '</span></h2>',
) );
register_sidebar( array(
    'name'          => esc_html__( 'Home 3', 'codilight-lite' ),
    'id'            => 'home-3',
    'description'   => '',
    'before_widget' => '<aside id="%1$s" class="home-widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h2 class="widget-title"><span>',
    'after_title'   => '</span></h2>',
) );
register_sidebar( array(
    'name'          => esc_html__( 'Home 4', 'codilight-lite' ),
    'id'            => 'home-4',
    'description'   => '',
    'before_widget' => '<aside id="%1$s" class="home-widget %2$s">',
    'after_widget'  => '</aside>',
    'before_title'  => '<h1 class="widget-title"><span>',
    'after_title'   => '</span></h1>',
) );

}

add_action('after_setup_theme','remove_parent_widgets');

function remove_parent_widgets() {
remove_action( 'widgets_init', 'codilight_lite_widgets_init' );
}
add_action( 'after_setup_theme', 'my_widgets_init' );
1
  • Glad you solved your own answer, be sure to click the checkmark next to your answer to indicate that this question has been solved. Sep 6, 2016 at 2:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.