WordPress Add Widget to Page Template

Start WP Add Widget to Page Template Example

1. Open functions.php and look for at least one PHP code block similar to:

register_sidebar( array(
'name' => __( 'Main Sidebar', 'twentyeleven' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );

2. After the last existing widget area registration, register your new widget area as follows (with your own name, id, description and theme name text):

register_sidebar( array(
'name' => __( 'custom-content-1', 'twentyeleven' ),
'id' => 'custom-content-1',
'description' => __( 'For use in a custom page template', 'twentyeleven' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );

3. In a new page template cloned from PAGE.PHP, add the following inside the content div, just below the php that calls the page content:

<!--?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("custom-content-1") ) : ?-->
<!--?php endif; ?-->

4. Create a new page using the template

End WP Add Widget to Page Template Example