How do I add a widget to the main body of a page?
-
I followed the instructions on Widgetizing Themes to add a widget area to a custom page template. Following the documentation, I added this to functions.php:
function arphabet_widgets_init() { register_sidebar( array( 'name' => 'Main widget area', 'id' => 'main_widget', 'before_widget' => '<div>', 'after_widget' => '</div>', 'before_title' => '<h2 class="rounded">', 'after_title' => '</h2>', ) ); } add_action( 'widgets_init', 'arphabet_widgets_init' );
and I added this to my custom template:
<?php if ( is_active_sidebar( 'main_widget' ) ) : ?> <div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary"> <?php dynamic_sidebar( 'main_widget' ); ?> </div><!-- #primary-sidebar --> <?php endif; ?>
This works, but it’s showing up as a sidebar and I want it to be in the main body of the page. The example in the documentation used the function dynamic_sidebar but I’m not sure what to do for a non-sidebar widget.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How do I add a widget to the main body of a page?’ is closed to new replies.