Add a custom sidebar to a WordPress theme or plugin

Create the sidebar in theme/plugin functions.php:

function my_sidebar() {
  register_sidebar(
    array (
      'name' => __( 'Custom', 'theme-domain' ),
      'id' => 'my-sidebar',
      'description' => __( 'My Sidebar', 'theme-domain' ),
      'before_widget' => '<div class="widget-content">',
      'after_widget' => "</div>",
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
    )
  );
}
add_action( 'widgets_init', 'my_sidebar' );

Display it in your WordPress theme:

<?php
  if(is_active_sidebar('my-sidebar')){
    dynamic_sidebar('my-sidebar' );
  }
?>

Leave a Reply

Your email address will not be published.