• 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)
  • Please post all the code for the custom page template. Obviously you are adding the code to the sidebar section of the code instead of the body where you want it.

    Sidebar is just a word it has no relation to where you place the code in the layout of the document.

    but it’s showing up as a sidebar

    possibly due to the html you are using in your code, i.e.:
    <div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">

    used the function dynamic_sidebar

    nothing to do with how the ‘sidebar’ aka widget area shows.
    the word sidebar is used generically in WordPress for any widget area

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.