Support » Fixing WordPress » Need conditional tag that detects presence of WP search box

  • 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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Does anyone out there have any suggestions about this?

    esmi

    (@esmi)

    Forum Moderator

    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?

    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; ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Need conditional tag that detects presence of WP search box’ is closed to new replies.