I followed the instructions here for how to add a widget to a template. I added this code to functions.php:
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Carousel',
'id' => 'carousel_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( 'carousel_widget' ) ) : ?>
<div id="carousel-widget" class="carousel widget-area">
<?php dynamic_sidebar( 'carousel_widget' ); ?>
</div>
<?php endif; ?>
It worked, but my new widget showed up as a sidebar, and I want it to be in the main body of the page. Obviously this is because of the dynamic_sidebar
function, but the documentation is not very helpful on how to place a widget on the page NOT as a sidebar.
I tried replaced the php with this:
<div id="carousel-widget" class="carousel widget-area">
<?php the_widget( 'carousel_widget' ); ?>
</div>
But now it doesn’t show up at all.
How do I place this widget on my page without it showing up as an absolutely positioned sidebar?