Skip to Content

hero_search()

Easily add a hero search form to a page.

PHP April 26, 2017

Usage

PHP
nebula()->hero_search($placeholder)

Parameters

$placeholder
(Optional) (String) The placeholder text for the form
Default: "What are you looking for?"

Request or provide clarification »

Source File

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

1 Hook

Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

Filters
"pre_nebula_hero_search"
Need a new filter hook? Request one here.

Actions
This function has no action hooks available. Request one?

PHP
    public function hero_search($placeholder=false){
        if ( empty($placeholder) ){
            $placeholder = __('What are you looking for?', 'nebula');
        }

        $override = apply_filters('pre_nebula_hero_search', null, $placeholder);
        if ( isset($override) ){return $override;}

        $form = '<div id="nebula-hero-formcon">
                <form id="nebula-hero-search" class="form-group search ignore-form" method="get" action="' . home_url('/') . '" role="search">
                    <div class="input-group">
                        <i class="fas fa-search"></i>
                        <label class="sr-only" for="nebula-hero-search-input">Autocomplete Search</label>
                        <input id="nebula-hero-search-input" type="search" class="form-control open input search nofade ignore-form" name="s" placeholder="' . $placeholder . '" autocomplete="off" tabindex="0" x-webkit-speech />
                    </div>
                </form>
            </div>';

        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_hero_search', 'my_custom_hero_search', 10, 2); //The last integer must be 1 more than the actual parameters
function my_custom_hero_search($null, $placeholder){ //$null is required, but can be ignored
    //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_hero_search', '__return_false');