1

I can't get my sidebar to appear on my site. I add a widget section since there wasn't any: function.php

<?php
if (function_exists('register_sidebar'))
    // Area 1
  register_sidebar( array (
  'name' => 'Primary Widget Area',
  'id' => 'primary_widget_area',
  'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  'after_widget' => "</li>",
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
  ) );

    // Area 2
  register_sidebar( array (
  'name' => 'Secondary Widget Area',
  'id' => 'secondary_widget_area',
  'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  'after_widget' => "</li>",
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
  ) );

    // Footer
  register_sidebar( array (
  'name' => 'Footer',
  'id' => 'footer_widget_area',
  'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  'after_widget' => "</li>",
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
  ) );
?>

sidebar.php

<?php dynamic_sidebar( 'sidebar-3' );  ?>

I'm following this tutorial: WordPress Widgets Tutorial And I've tried many online examples and here are two: wordpress custom modules/widget areas on the page? can i make my own? and Widgetizing Themes

3

Your have created three sidebars and that are primary_widget_area, secondary_widget_area, footer_widget_area

But in the sidebar, you call a different sidebar name sidebar-3; that's why your sidebars are not displaying.

Try the following code in sidebar.php:

// To display primary_widget_area sidebar
<?php if ( is_active_sidebar( 'primary_widget_area' ) ) : ?>
    <?php dynamic_sidebar( 'primary_widget_area' ); ?>
<?php endif; ?>

// To display secondary_widget_areasidebar
<?php if ( is_active_sidebar( 'secondary_widget_area' ) ) : ?>
    <?php dynamic_sidebar( 'secondary_widget_area' ); ?>
<?php endif; ?>

// To display footer_widget_areasidebar
<?php if ( is_active_sidebar( 'footer_widget_area' ) ) : ?>
    <?php dynamic_sidebar( 'footer_widget_area' ); ?>
<?php endif; ?>

Thank you!

  • How do I mark this as resolved? – Kim Apr 11 '16 at 20:36
  • I am not sure as I am new here. I search around the web and I found the following: – Hasibur Rahman Apr 11 '16 at 21:14
  • Click the green outlined checkmark to the left of the answer that solved your problem. This marks the answer as "accepted", and by extension the question as "has an accepted answer". – Hasibur Rahman Apr 11 '16 at 21:15
  • @hasibrsohel - why all the if statements? – Michael Apr 12 '16 at 4:21
  • @Michael - Sorry, I could not understand your query. – Hasibur Rahman Apr 12 '16 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.