How do I add a global search form to the header?

Is there any way to add a Global Search form to the header of a website?

  • Vaughan

    hiya

    The global site search plugin comes with a widget. this makes it particularly easy to add to the header with a bit of custom coding in your theme.

    which theme are you using?

    you could just add the following to your functions.php

    if (function_exists('register_sidebar')) {
    register_sidebar(array(
    'name' => 'Header Widgets',
    'id' => 'header-widgets',
    'description' => 'The header widgets for your website.',
    'before_widget' => '<div id="%1$s" class="widget %2$s">',
    'after_widget' => '</div>',
    'before_title' => '<h2>',
    'after_title' => '</h2>'
    ));
    }

    then add this in header.php wherever you want the widget to show.

    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Header Widgets')) :
    endif; ?>

    once done, you should be able to see a new widget area in dashboard > appearances > widgets, you can then add the global site search widget to this new sidebar and it should display.

    if you struggle to do this yourself, let me know which theme you are using & i'll do this for you.

    hope this helps

  • Julien

    Thank you that works great. Would you be able to help me figure out how to get the search to look like the original search on the theme? I am using Activello and made a child theme. I made the code switch but not sure if just changing input type from text to search will do the trick or if it is more complicated.
    Here is what the search should look like: https://colorlib.com/activello/
    I activated support access. thank you!