Post this code in your theme function.php
// Register Sidebar add_action( 'widgets_init', 'mytheme_sidebar_init' ); function mytheme_sidebar_init() { register_sidebar( array( 'name' => esc_html__( 'Main_sidebar', 'clean' ), 'id' => 'primary-widget-area', 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); }
Now you can output the sidebar to any file in your theme, such as single.php
To do this, use the code below.
In which it is necessary to transfer id to a sidebar which needs to be displayed
<?php dynamic_sidebar('primary-widget-area'); ?>
But if you need to change the wrapper of your sidebar, you need
change
<?php dynamic_sidebar('primary-widget-area'); ?>
on
<?php get_sidebar('nameformysidebarfile'); ?>
Then create in your theme directory file sidebar-nameformysidebarfile.php and in it already add
dynamic_sidebar('primary-widget-area');
For exemple
<aside id="sidebar" role="complementary"> <?php if ( is_active_sidebar( 'primary-widget-area' ) ) : ?> <div id="primary" class="widget-area"> <ul class="xoxo"> <?php dynamic_sidebar( 'primary-widget-area' ); ?> </ul> </div> <?php endif; ?> </aside>