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

  1. sc456a
    Posted 3 years 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
    Posted 3 years ago #

    Does anyone out there have any suggestions about this?

  3. esmi
    Forum Moderator
    Posted 3 years ago #

  4. sc456a
    Posted 3 years 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
    Posted 3 years 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') ) : ?>
    <?php else : ?>
    <h1>Not Active</h1>
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic