I just need to check, if sidebar has any content

My functions.phpcode is below.

function aspirationas_extra_widget_1_init() {

register_sidebar(array(
    'name' => __('Extra Widget 1', 'aspirations'),
    'id' => 'extra_widget_1',
    'description' => __('Widgets for Extra 1', 'aspirations'),
    'before_widget' => '<aside>',
    'after_widget' => '</aside>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
));
}

add_action('widgets_init', 'aspirationas_extra_widget_1_init');

And I read this widget by this code below.

dynamic_sidebar('extra_widget_1');

I am beginner in wordpress development. I know this is a sili question, but I can not solved it. any one help me please.

1 Answer
1

Problem solved by this code below:

<?php if (is_active_sidebar('extra_widget_1')) {
     ?>
     <li>
          <?php dynamic_sidebar('extra_widget_1'); ?>
     </li>
 <?php
     }
 ?>

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *