• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

if loop condition for widgets

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › if loop condition for widgets

This topic is: not resolved

Tagged: Eleven40

  • This topic has 1 reply, 2 voices, and was last updated 12 years, 11 months ago by SoZo.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • February 2, 2013 at 11:00 am #17366
    iaditya999
    Member

    I have created two widget areas using this code...

    When widgets are added to this areas they are also showing up on blog page or anywhere.

    So how do I apply if loop condition here ??????????? And which condition to apply so they will be showing only on respective page.

    /** before content ads */
    genesis_register_sidebar( array(
    'id' => 'before content ad',
    'name' => 'before content ad',
    'description' => 'This is a sidebar that goes before the content and is mostly for advertising.',
    ) );

    add_action( 'genesis_before_post_content', 'child_before_content_ad_sidebar' );
    /** Loads a new sidebar after the content */
    function child_before_content_ad_sidebar() {

    echo '<div class="before content ad">';
    dynamic_sidebar( 'before content ad' );
    echo '</div>';

    }

    /** after content ad */
    genesis_register_sidebar( array(
    'id' => 'after-content-ad',
    'name' => 'After Content Ad',
    'description' => 'This is a sidebar that goes after the content.',
    ) );

    add_action( 'genesis_after_post_content', 'child_after_content_ad_sidebar' );
    /** Loads a new sidebar after the content */
    function child_after_content_ad_sidebar() {

    echo '<div class="after-content-ad">';
    dynamic_sidebar( 'after-content-ad' );
    echo '</div>';

    }

    February 2, 2013 at 3:25 pm #17424
    SoZo
    Member

    For pages you use is_page(), e.g.

    add_action( ‘genesis_after_post_content’, ‘child_after_content_ad_sidebar’ );
    /** Loads a new sidebar after the content */
    function child_after_content_ad_sidebar() {
    if( is_page('1'))
    echo ‘<div class=”after-content-ad”>’;
    dynamic_sidebar( ‘after-content-ad’ );
    echo ‘</div>’;
    
    }

    You can learn about conditional tags here.


    John “Nicolas Flamel” Wright | SoZo’s design| John Wright Photography

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble