I’m taking a Udemy class to learn how to make WordPress plugins and themes. The video I’m on is having me override the default search widget with a custom one via searchform.php. From what I’ve gathered, this file should automatically be loaded with the rest of the theme as long as I have followed these steps:
/theme_dir/functions.php
/* Some other code */
include ( get_theme_file_path('/includes/widgets.php') );
add_action("widgets_init", 'ju_widgets');
/theme_dir/includes/widgets.php
function ju_widgets() {
register_sidebar([
'name' => __('My First Theme Sidebar', 'udemy'),
'id' => 'ju_sidebar',
'description' => __('Sidebar for the theme Udemy', 'udemy'),
'before_widget' => '<div id="%1$s" class="widget clearfix %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
]);
}
/theme_dir/sidebar.php
<div class="sidebar nobottommargin col_last">
<div class="sidebar-widgets-wrap">
<?php
if (is_active_sidebar('ju_sidebar')) {
dynamic_sidebar('ju_sidebar');
}
?>
</div>
</div>
/theme_dir/searchform.php
<?php $unique_id = esc_attr( uniqid( 'search-form-' ) ); ?>
<form role="search" method="get" class="search-form"
action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="input-group">
<input type="search" id="<?php echo $unique_id; ?>"
class="form-control" name="s"
value="<?php the_search_query(); ?>"
placeholder="<?php _e( 'Search', 'udemy' ); ?>"/>
<span class="input-group-btn">
<button type="submit" class="btn btn-danger"><i class="icon-search"></i></button>
</span>
</div>
</form>
/theme_dir/index.php
<!-- some theme html -->
<?php get_sidebar(); ?>
<!-- other theme html -->
No matter what I change in the searchform.php file, it doesn’t replace the default search widget.