Last active
May 26, 2017 17:25
-
-
Save tylerforret/655f9364def8f42529d228be589741c7 to your computer and use it in GitHub Desktop.
Wordpress Default Search + In-Site Google CSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Create or edit "searchform.php" in theme folder | |
Replace what is there with the google cse script - example below | |
**Note: You will need to edit the final line outside the script with the custom parameters: resultsUrl & queryParameterName | |
--> | |
<script> | |
(function() { | |
var cx = '007001040030262277022:mmdp7u94c6u'; | |
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); | |
})(); | |
</script> | |
<gcse:searchbox-only resultsUrl="/" queryParameterName="s"></gcse:searchbox-only> | |
<!-- now find or create search.php in your theme to create a results page, then include the code below --> | |
<gcse:searchresults-only queryParameterName="s"></gcse:searchresluts-only> | |
<!-- I also like to use the following php snippet for the page title for a custom header --> | |
<h1><?php printf( __( 'Search Results for: %s', 'betfirm' ), '<span>' . get_search_query() . '</span>' ); ?></h1> | |
<!-- Now I can reference <?php get_search_form(); ?> anywhere in my theme and keep the results on the default wordpress search results page--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment