WordPress.org

Forums

[resolved] New custom widget area (13 posts)

  1. fz11
    Member
    Posted 2 years ago #

    Hello
    I have created a new custom widget area next to a front page slider. i am using a image widget to upload an image.

    the issue I have is the new widget area is displayed in all other pages as well even when I switch to full width which normally should not display. how do I get it just to display on the front/home page.

    this is what I've done:

    register_sidebar(array(
    'name' => __('Top Bar'),
    'id' => 'topbar',
    'description' => __('The widgetized top bar. Drag and drop widgets from the left'),
    'before_widget' => '<div id="%1$s" class="widgets">',
    'after_widget' => '</div>',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));

    and header php:

    <?php /* Widgetized sidebar */
    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Top Bar') ) : ?><?php endif; ?>
    </div>

    is there anything I can do without too much complications?

  2. Frumph
    Member
    Posted 2 years ago #

    if ( is_home() ) dynamic_sidebar('Top Bar');

    check if it's the homepage with is_home() you don't need the function_exists part anymore

  3. fz11
    Member
    Posted 2 years ago #

    thanks you mean replace the header code with above?

  4. fz11
    Member
    Posted 2 years ago #

    I tried this

    <?php /* Widgetized sidebar */
    if ( is_home() )('dynamic_sidebar') || !dynamic_sidebar('Top Bar') ) : ?><?php endif; ?>
    </div>

    the whole site went white!!!

  5. Michael
    Forum Moderator
    Posted 2 years ago #

    thanks you mean replace the header code with above?

    more-or-less yes;

    replace:

    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Top Bar') ) : ?><?php endif; ?>

    with:

    if ( is_home() ) dynamic_sidebar('Top Bar');

  6. fz11
    Member
    Posted 2 years ago #

    I tired this and went all white again

    used this
    <?php if ( is_home() ) dynamic_sidebar('Top Bar');
    <?php endif; ?>

    instead of

    <?php /* Widgetized sidebar */
    if ( is_home() )('dynamic_sidebar') || !dynamic_sidebar('Top Bar') ) : ?><?php endif; ?>
    </div>

  7. Frumph
    Member
    Posted 2 years ago #

    ... remove the <?php endif; ?> part

  8. Frumph
    Member
    Posted 2 years ago #

    <?php if ( is_home() ) dynamic_sidebar('Top Bar'); ?>

    .. that's all.

  9. fz11
    Member
    Posted 2 years ago #

    ok now widget area not displaying anything at all

  10. Frumph
    Member
    Posted 2 years ago #

    Are you using a static page as your front page in the settings -> reading?

  11. fz11
    Member
    Posted 2 years ago #

    yes its static

  12. Frumph
    Member
    Posted 2 years ago #

    then use is_front_page() instead of is_home()

  13. fz11
    Member
    Posted 2 years ago #

    it worked
    thanks a lot :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.