Skip to Content

mobileSearchPlaceholder()

Change the search input placeholder from “What are you looking for?” to just “Search” for narrow viewports (mobile).

JavaScript February 7, 2021

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Additional Notes

This function triggers the change at 410px wide viewport.

Source File

Located in /assets/js/modules/search.js on line 263.

1 Hook

Find these filters and actions in the source code below to hook into them. Use wp.hooks.doAction() and wp.hooks.addFilter() in your JavaScript file.

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

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

JavaScript
nebula.mobileSearchPlaceholder = async function(){
    let mobileHeaderSearchInput = jQuery('#mobileheadersearch input');
    let searchPlaceholder = wp.hooks.applyFilters('nebulaMobileSearchPlaceholder', 'What are you looking for?');

    if ( window.matchMedia('(max-width: 410px)').matches ){
        searchPlaceholder = 'Search';
    }
    mobileHeaderSearchInput.attr('placeholder', searchPlaceholder);
};

Override

To override or disable this JavaScript function, simply redeclare it with the exact same function name.

JavaScript
nebula.mobileSearchPlaceholder = function(){
    //Write your own code here, leave it blank, or return false.
}