Prevent Empty Searches in the Divi Search Box

|

By default, an empty search in Divi will result in the display of all posts on the search page. Here's how to prevent empty searches.

Prevent Empty Searches in the Default Header Search Box

To prevent empty searches in the search box revealed by the search icon in the main Divi header, you can use the following jQuery code:

<script>
jQuery(
	function($){
		$('.et-search-field').prop('required',true);
	}
);
</script>
This will notify the user that the field must be filled in, like so:

Prevent Empty Searches in the Divi Search Module

To prevent empty searches in the search box added by a Divi search module, you can use the following jQuery code:

<script>
jQuery(
	function($){
		$('.et_pb_search .et_pb_s').prop('required',true);
	}
);
</script>

This post may contain referral links which may earn a commission for this site

Divi Booster

Hundreds of new features for Divi
in one easy-to-use plugin

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.