Environment: WP 3.5, Twenty Twelve child theme. I created a custom template. Now, I'd like to display the built-in sidebar-2 in this custom template page (instead of the default sidebar-1). sidebar-2 is already registered by twenty twelve functions.php. I read a bit about get_sidebar and how to activate other sidebars, but I'm still a bit confused. To activate sidebar-2 on this custom template I created a file sidebar-customtemplate.php in my child theme directory with this content:

<?php if ( is_active_sidebar( 'sidebar-2' ) ) : ?>
    <div id="secondary" class="widget-area" role="complementary">               
        <?php dynamic_sidebar( 'sidebar-2' ); ?>
    </div><!-- #secondary -->
<?php endif; ?>

Then in my custom template file I replaced get_sidebar(); with <?php get_sidebar( $customtemplate ); ?>. Then I added some widgets to the sidebar-2 (from Appearance - Widget), but in the home page still sidebar-1 is displayed! Why? :(

4 Answers 4


you can put this code in your functions

add_action( 'init', 'register_my_menus' );
function register_my_menus() {
            'menu-1' => __( 'Head' )

and this code, in the place you want your second menu

<?php wp_nav_menu( array( 'theme_location' => 'menu-1' ) ); ?>

and than, you can control your new menu, through the menu section in the admin panel

  • Uhm, no. I don't need to register a menu. I need to use the already registered by default (in twenty twelve) "sidebar-2" in a custom template page. Commented Dec 23, 2012 at 15:31
  • Oh, sorry, i didnt noticed. did you check if its passing the if condition? Commented Dec 23, 2012 at 15:37
<?php get_sidebar( 'customtemplate' ); ?> 

did the thing :)


Rename that sidebar-2 into sidebar-sidebar2.php and after use this code

<?php get_sidebar('sidebar2');?>

hope its may work


Did you create a CSS that includes both left and right side bars?

    2 sidebars
---------------------------------------------------- */
#sidebar {
#sidebar-core {
#main {
    float: left;
    width: 65%;
    display: block;
#main-core {
    margin-right: 20px;
    margin-left: 20px;
#sidebarright {
    display: block;
    float: left;
    width: 15%;
#sidebarright-core {
    margin-left: 20px;

Upload this in your styles in your theme. Name it something like two-sidebars.css, then go to your functions.php and require this once. You will have to define the path, an example is like this:

wp_register_style( 'twosidebars', get_template_directory_uri() . '/styles/layouts/two-sidebar.css', '', '1.1' );

You will see the other sidebar options for requirements. Model what you do off that.

Now you will need a new sidebar.php that calls the CSS, so create a new one and name it something like sidbar2.php and insert something like this:

<div id="sidebar">
        <div id="sidebar-core">    
            <?php do_action( 'before_sidebar' ); ?>
            <?php if ( ! dynamic_sidebar() get_sidebar() ); ?>   
</div><!-- #sidebar -->

<div id="sidebarright">
        <div id="sidebarright-core">
            <?php do_action( 'before_sidebar' ); ?>
            <?php if ( ! dynamic_sidebar() get_sidebar(sidebar2) ); ?>   
</div><!-- #sidebar2 -->

Now all of this assumes you have already registered the array sidebar2 as an array in your functions.php. This also assumes you edited your stylesheet to include a separate style for sidebar2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.