php - Updating Google Custom Search CSE on custom Wordpress theme -
i don't have experience in php i'm trying update website's custom theme code use new google cse. website set header has search bar redirects search results page. search bar code in header.php follows:
<form method="get" action="<?php bloginfo('url'); ?>" class="ui-form dark search"> <label for="f-search"><i class="icon-search"></i> <span class="alt">search</span></label> <input type="text" name="s" id="f-search" placeholder="search" /> </form>
the search results page:
<script src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('search', '1'); google.setonloadcallback(function() { var search = new google.search.customsearchcontrol('010282947182076583221:xjxtd-etbp0'); search.draw('search-results'); search.execute("<?php the_search_query(); ?>"); }); </script>
this new cse code google:
<script> (function() { var cx = '015983680008294815385:py6fsnsv2fc'; 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:search></gcse:search>
any appreciated! thanks!
just replace old html code
<form method="get" action="<?php bloginfo('url'); ?>" class="ui-form dark search"> <label for="f-search"><i class="icon-search"></i> <span class="alt">search</span></label> <input type="text" name="s" id="f-search" placeholder="search" /> </form>
with
<script> (function() { var cx = '015983680008294815385:py6fsnsv2fc'; 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:search></gcse:search>
that's start working.. (now have replaced default search google custom search)
Comments
Post a Comment