WordPress: Adding a widget area to the primary page template?

I’m trying to add a widget area to the main body of page.php, so that I can place unique widgets on each page of my site. I’ve followed the instructions here: http://codex.wordpress.org/Widgetizing_Themes

I added this to functions.php in my theme:

Read More
function arphabet_widgets_init() {

    register_sidebar( array(
        'name'          => 'Main widget',
        'id'            => 'main_widget_area',
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="rounded">',
        'after_title'   => '</h2>',
    ) );

}
add_action( 'widgets_init', 'arphabet_widgets_init' );

and this is page.php:

get_header(); ?>

    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">

        <?php if ( is_active_sidebar( 'main_widget_area' ) ) : ?>
            <div id="main-widget" class="widget-area main-widget">
                <?php dynamic_sidebar( 'main_widget_area' ); ?>
            </div><!-- #primary-sidebar -->
        <?php endif; ?>

            <?php /* The loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <header class="entry-header">
                        <?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
                        <div class="entry-thumbnail">
                            <?php the_post_thumbnail(); ?>
                        </div>
                        <?php endif; ?>

                        <h1 class="entry-title"><?php the_title(); ?></h1>
                    </header><!-- .entry-header -->

                    <div class="entry-content">
                        <?php the_content(); ?>
                        <?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
                    </div><!-- .entry-content -->

                    <footer class="entry-meta">
                        <?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
                    </footer><!-- .entry-meta -->
                </article><!-- #post -->

                <?php comments_template(); ?>
            <?php endwhile; ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

(I added the top section, with main_widget_area)

However when I edit the page I see no way to drop in a widget. I’m not sure if I’m missing a step, or if I’m just not editing the page in the right way.

Related posts

1 comment

  1. Take a look at the “Widgets” menu underneath “Appearance” in the WordPress backend. There will be a list of widgets on the left side of the page and a list of available sidebars on the right. Just drag-and-drop the widget you want into the sidebar you registered and you should be good to go.

Comments are closed.