• I used the following code to achieve a new div above the header.

    function pagetopwidget() {
    
    	echo '<div id="pagetopwidget">
    
    		</div>';
    
    }

    I have registered a new widget ‘Top Page Widget’

    But how do I insert the widget in to the above code so it will appear in that div?

    I tried to insert in this code between the <div> tags but no luck, maybe missing some important piece of php.

    <?php if (!dynamic_sidebar('Top Page Widget')) : ?>
                    <div class="toppagewidget">
    
                        <div class="wrap">
                            <p><?php _e("This is a widgeted area which is called Top Page Widget"); ?></p>
                        </div><!-- end .wrap -->
                    </div><!-- end .widget -->
                <?php endif; ?>
Viewing 1 replies (of 1 total)
  • You would need to use the id that you assigned when registering this widget, rather than the name, as well as add the dynamic sidebar code, that I added in the below set.

    <?php if (!dynamic_sidebar('id-of-widget-here')) : ?>
                    <div class="toppagewidget">
                        <div class="wrap">
                            <p><?php _e("This is a widgeted area which is called Top Page Widget"); ?></p>
                             //add the following line and replace the id
                             <?php dynamic_sidebar('id-of-widget-here-as-well'); ?>
                        </div><!-- end .wrap -->
                    </div><!-- end .widget -->
                <?php endif; ?>

    Lemme know if that ends up working for ya, or if you need more explanation.

Viewing 1 replies (of 1 total)
  • The topic ‘How to add a new widget area into a specific div in functions.php’ is closed to new replies.