Widgetizing theme in wordpress - 7-Views
Widgetizing theme in wordpress
Widgetizing is creating widget area in your theme. For this you need to add below code inside your functions.php file
function mytheme_widgets_init() { register_sidebar( array( 'name' => 'Sidebar Right', 'id' => 'sidebar_right', 'before_widget' => '<div>', 'after_widget' => '</div>', 'before_title' => '<h2>', 'after_title' => '</h2>', ) ); } add_action( 'widgets_init', 'mytheme_widgets_init' );
Once added look into your widget area a new widget section will be there named by Sidebar Right
After creating the widget section we need to display the widget section. For this add the code directly to a theme file like the sidebar.php file;
<?php if ( is_active_sidebar( 'sidebar_right' ) ) : ?> <div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary"> <?php dynamic_sidebar( 'sidebar_right' ); ?> </div><!-- #primary-sidebar --> <?php endif; ?>