Custom Sidebars

Register Custom Sidebars in THEME/functions.php

add_action( 'widgets_init', 'my_register_sidebars' );

function my_register_sidebars() {

register_sidebar( array(
'name' => __( 'Primary Widget Area'),
'id' => 'primary-widget-area',
'description' => __( 'The primary widget area' ),
'before_widget' => '

  • ',
    'after_widget' => '
  • ',
    'before_title' => '

    ',
    'after_title' => '

    ',
    ) );

    register_sidebar(array(
    'id' => 'topwidget',
    'name' => __('Top Widget'),
    'description' => __('Widget area between nav bar and content on index page'),
    'before_widget' => '

  • ',
    'after_widget' => '
  • ',
    'before_title' => '

    ',
    'after_title' => '

    ' . "nt"
    ));
    register_sidebar(array(
    'id' => 'shop',
    'name' => __('Shop Sidebar'),
    'description' => __('Sidebar for shop custom post type'),
    'before_widget' => '

  • ',
    'after_widget' => '
  • ',
    'before_title' => '

    ',
    'after_title' => '

    ' . "nt"
    ));
    }

    Create sidebar-mycustom.php.
    You will see your sidebars now listed in ‘Appearance’ -> ‘Widgets’.

    In your sidebar-templates you may now call the dynamic generated content (widgets) by the name of your sidebars eg in sidebar-mycustom.php:


    ... regular html ...

    ... regular html ...

    Integrate your sidebars in your template-files (e.g. index.php, single.php, archives.php):

    Default sidebar:

    Custom Sidebar:

    Notes:

    • sidebar file name does not need to be relates to the registered sidebar name
    • registered name is used to call the dynamic sidebar eg: custom
    • custom sidebar file is called from template using get_sidebar(‘mycustom’)

    Leave a Comment