Skip to Content

search_form()

Modify the WordPress search form to use Bootstrap components.

PHP July 12, 2017

Usage

PHP
nebula()->search_form()

Parameters

This function does not accept any parameters. Is this incorrect?

Additional Notes

This function is used to replace core WordPress search forms, but also can be called manually.

Source File

Located in /libs/Functions.php on line 1548.

PHP
    public function search_form(){
        $override = apply_filters('pre_nebula_search_form', null);
        if ( isset($override) ){return;}

        $placeholder = ( get_search_query() )? get_search_query() : 'Search';

        $form = '<form id="searchform" class="form-group form-inline ignore-form" role="search" method="get" action="' . home_url('/') . '">
                    <div class="input-group mb-2 mr-sm-2 mb-sm-0">
                        <div class="input-group-addon mb-2"><i class="fa fa-search"></i></div>
                        <label class="sr-only" for="s">Search</label>
                        <input id="s" class="form-control ignore-form mb-2" type="text" name="s" value="' . get_search_query() . '" placeholder="' . $placeholder . '" role="search" />
                    </div>

                    <button id="searchsubmit" class="btn btn-brand wp_search_submit mb-2" type="submit">Submit</button>
                </form>';

        return $form;
    }

Override

To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

PHP
add_filter('pre_nebula_search_form', 'my_custom_search_form'); 
function my_custom_search_form(){ 
    //Write your own code here

    return true; //Return true to prevent the original function from running afterwords
}

You can completely disable this PHP function with a single line actions:

PHP
 add_filter('pre_nebula_search_form', '__return_false');