New Topic

Custom widget areas failing in Pro

Home › Forum › Customization › Custom widget areas failing in Pro

This topic contains 3 replies, has 2 voices, and was last updated by  StartupWP 2 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1685

    osakawebbie
    Member

    When I was working with a child of the free Startup theme, I successfully created two new widget areas in the header. Now I have bought StartupPro and tried to transfer my relevant code to the startuppro-child theme, but the widget areas aren’t working. What is different between regular and Pro that might affect this?

    The code changes I do are as follows. I add a functions.php with the following:

    <?php
    add_action( 'widgets_init', 'startupchild_widgets_init' );
    function startupchild_widgets_init() {
      register_sidebar( array (
      'name' => __( 'Banner Center Widget Area', 'startup' ),
      'id' => 'bannercenter-widget-area',
      'before_widget' => '<div id="%1$s">',
      'after_widget' => "</div>",
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
      ) );
      register_sidebar( array (
      'name' => __( 'Banner Right Widget Area', 'startup' ),
      'id' => 'bannerright-widget-area',
      'before_widget' => '<div id="%1$s">',
      'after_widget' => "</div>",
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
      ) );
    }
    ?>

    Then I copy header.php from the parent theme to the child, and edit it to add this code between the site description and the nav menu:

    <?php if ( is_active_sidebar('bannerright-widget-area') ) : ?>
    <div id="bannerright" class="widget-area">
    <?php dynamic_sidebar('bannerright-widget-area'); ?>
    </div>
    <?php endif; ?>
    <?php if ( is_active_sidebar('bannercenter-widget-area') ) : ?>
    <div id="bannercenter" class="widget-area">
    <?php dynamic_sidebar('bannercenter-widget-area'); ?>
    </div>
    <?php endif; ?>
    #1688

    StartupWP
    Support

    No need to add the additional function, just register the new widget areas below:

    register_sidebar( array (
    'name' => __( 'Content Widget Area', 'startup' ),
    'id' => 'content-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>',
    ) );

    Like so:

    register_sidebar( array (
    'name' => __( 'Content Widget Area', 'startup' ),
    'id' => 'content-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>',
    ) );
    register_sidebar( array (
    'name' => __( 'Banner Center Widget Area', 'startup' ),
    'id' => 'bannercenter-widget-area',
    'before_widget' => '<div id="%1$s">',
    'after_widget' => "</div>",
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
    ) );
    register_sidebar( array (
    'name' => __( 'Banner Right Widget Area', 'startup' ),
    'id' => 'bannerright-widget-area',
    'before_widget' => '<div id="%1$s">',
    'after_widget' => "</div>",
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
    ) );
    #1689

    osakawebbie
    Member

    That simplified the code, but didn’t change the symptom. However, I assumed the widget areas weren’t working because nothing was showing in the header – I didn’t check the Admin side (duh!). I don’t know what the situation looked like while I was putting the theme together, but at the moment the widget areas are all there; the reason nothing was showing correctly (and my tagline was appearing in the sidebar, which was crazy), is that at some point WordPress pushed all the widgets “down” two areas from where they were before! So my Banner Center widget was in Sidebar Widget Area, the Banner Right widget was in Left Sidebar Widget Area (which doesn’t actually appear), and my real sidebar widgets were in Right Sidebar Widget Area (which doesn’t appear). I have moved them all back now, and all is well. :-)

    #1692

    StartupWP
    Support

    Yeah, that’s a common quirk with WordPress. Another thing to look out for when making changes and WP gets confused about widgets, is that they’ll be dropped down under Inactive Widgets. So luckily, they’ll never be lost, just need to be rearranged sometimes if you’re registering/unregistering widget areas.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.