WordPress Theme from scratch, widgets don’t work

I know this topic has been discussed quite a bit but I’ve tried everything I can find online and nothing is working. I need a single widget area in my custom template. I wrote if from scratch and didn’t use a barebones type starter therefore I didn’t have a functions.php to start from.

In wp-admin it shows my widget as it should but when there is a widget in that area and the page is reloaded it resets. in other words the widget doesn’t persist in the area it’s supposed to. am I missing something? is my wordpress install bad?

Read More

here is my functions.php in it’s entirety

<?php
register_sidebar
    (
        array(
            'name' => 'Header Widget',
        'id' => 'headerBanner',
        'before_widget' => '<div id="banner">',
        'after_widget' => '</div>',
        'before_title' => '',
        'after_title' => '',
    )
)

?>

and my index.php

<?php if ( !dynamic_sidebar (1)) : ?>
<h1>it didn't work</h1>
<?php endif; ?>

Related posts

Leave a Reply

2 comments

  1. try:

    <?php if(!dynamic_sidebar ('headerBanner')) : ?>
    <h1>it doesn't work</h1>
    <?php endif; ?>
    

    You need to pass the id of the sidebar you want to display when calling dynamic_sidebar

    Also note that dynamic_sidebar will return false if there are no widgets added to the sidebar so add a widget to it and see if it works