WordPress.org

Support

Support » How-To and Troubleshooting » one widget, different placement depending on page/post

one widget, different placement depending on page/post

  • I have two widgets that are to be used for a plugin.

    In homepage I want it shows up in non-sidebar section (widget1); in single post it will shows on the sidebar (widget2) and I have it placed in the sidebar.php which contains other widgets that are to be used globally.

    The problem is, widget2 also show up in the homepage sidebar which I don’t want.

    I suppose I can create a second template for sidebar which exclude “widget2”, but I would like to know if it’s possible to use just one template with “is_front_page()” tag.

    I tried using this code but it’s not really working as the “widget2” still showing up in the homepage.

    <?php if ( is_front_page() && !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(“widget2”) ) : ?>
    <?php endif; ?>

    Have searched the forum but I can’t find anything that works for me.

Viewing 1 replies (of 1 total)
  • Never mind! I got it working with this:

    <?php if (!is_front_page()) {?>
    <?php
    if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(“widget2”) ) : ?>
    <?php endif; ?>
    <?php }?>

Viewing 1 replies (of 1 total)
  • The topic ‘one widget, different placement depending on page/post’ is closed to new replies.