Skip to content

Snippet: Override All Search Forms with Google Search

Below is a snippet showing how you can override all the searchforms in Total (and any WordPress theme that correctly uses the get_search_form() function). Make sure to replace 'YOUR_ENGINE_ID' and also you may have to do some additional styling to make it look good after it's implemented since the Google search will have different classnames/elements.

add_action( 'get_search_form', function() {
	ob_start(); ?>

	
	(function() {
		var cx = 'YOUR_ENGINE_ID';
		var gcse = document.createElement('script');
		gcse.type = 'text/javascript';
		gcse.async = true;
		gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
		var s = document.getElementsByTagName('script')[0];
		s.parentNode.insertBefore(gcse, s);
	} )();
	
	

	<?php
	return ob_get_clean();
} );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top