WordPress.org

Ready to get started?Download WordPress

Forums

Need conditional tag that detects presence of WP search box (5 posts)

  1. sc456a
    Member
    Posted 1 year ago #

    I'm working on a theme update and need some kind of tag or if/else that can determine if the search box is present on the page already and only display the code for the second box if it isn't. This way the search box will only appear once per page. Anyone have any ideas?

  2. sc456a
    Member
    Posted 1 year ago #

    Does anyone out there have any suggestions about this?

  3. esmi
    Forum Moderator
    Posted 1 year ago #

  4. sc456a
    Member
    Posted 1 year ago #

    Actually that would probably work. I can't wrap my head around the syntax though. It would need to check to see if the search widget is active, and if not, display the search box.

    It looks like the global for the search widget is wp_widget_search. I might be wrong on that. Any idea what the PHP code would be to achieve this?

  5. sc456a
    Member
    Posted 1 year ago #

    Here is the code I'm testing with but it always shows "Not Active" even though the search widget is in the sidebar. I've tried using widget_search and wp_widget_search, same results:

    <?php if ( is_active_widget('widget_search') ) : ?>
    <h1>Active</h1>
    <?php else : ?>
    <h1>Not Active</h1>
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic