I am trying to override some behaviour in a parent theme (Blackoot Lite) and used this StackOverflow question as a guide.
My goals are twofold—I want to unregister a default sidebar in the parent theme, plus I want to add a custom header widget area. Neither thing ends up happening. 😒
Below is my code, which I put into the child theme's functions.php:
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
function wpb_widgets_init() {
register_sidebar( array(
'name' => 'Custom Header Widget Area',
'id' => 'custom-header-widget',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="chw-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'wpb_widgets_init' );
function blackoot_lite_unregister_sidebar() {
unregister_sidebar('sidebar');
unregister_sidebar('footer-sidebar');
}
add_action( 'after-setup-theme', 'blackoot_lite_unregister_sidebar' );
Any advice would be much appreciated.
if ( is_active_sidebar( 'particular-sidebar' ) ) dynamic_sidebar( 'particular-sidebar' );You could also remove the unwanted sidebar by removing these lines. But first you should find these places in the parent theme, copy those files over to your child theme, and change them accordingly. Also you should check in your parent theme where is the widget added, and remove it according to that. "after-setup-theme" may not be a good 'place'.after-setup-themedoesn't exist in WordPress core. it may be the actionafter_setup_theme?