how to add google custom search to the existing search box?

  • desai_amogh



    Kindly advise how can i integrate the google CSE in my searchform.

    Please see the code in my searchform.php below:

    <form id="searchform" class="searchform" method="get" action="<?php echo get_home_url(); ?>">
    <p class="clearfix default_searchform">
    <input type="text" name="s" onblur="if (this.value == '') {this.value = '<?php _e('Search','graphene'); ?>';}" onfocus="if (this.value == '<?php _e('Search','graphene'); ?>') {this.value = '';}" value="<?php _e('Search','graphene'); ?>" />
    <button type="submit"><span><?php _e('Search', 'graphene'); ?></span></button>
    <?php do_action('graphene_search_form'); ?>

    And this is the new google CSE code

    <div id="cse-search-form" style="width: 100%;">Loading</div>
    <script src="" type="text/javascript"></script>
    <script type="text/javascript">
    google.load('search', '1', {language : 'en', style : google.loader.themes.MINIMALIST});
    google.setOnLoadCallback(function() {
    var customSearchOptions = {}; var customSearchControl = new
    'xxxxxxxxxxxxxxxxxxxxxxxxxxx:xxxxxxxxxxx', customSearchOptions);
    var options = new;
    customSearchControl.draw('cse', options);
    }, true);

    <style type="text/css">

    ***Style info snipped by moderator***





    Kenneth John Odle


    You can’t add Google custom search to the existing search box. You have to replace it.

    In the “Header Display Options”, turn off the search feature. Then, use a Graphene action hook widget area and a text widget to insert the above code into your site. Use the graphene_top_search or graphene_top_bar widget area. (You may have to try different ones.)

    How to use action hook widget areas:

    As for all the styling information you included (I snipped it; we don’t really need to know it here), you will want to drop that into either Graphene’s built in Custom CSS feature or into your child theme’s style sheet. Given the amount of code this includes, I highly recommend using a child theme and adding it to your child theme’s style sheet so as not to drag down your site’s performance.





    Hey Kenneth,

    Thanks alot for your reply. This solution did work, that too without the css, with just the code you gave me above. There is a problem though.

    check it here:

    the search box apears and has all the styling, but the search button doesnt work.


    Kenneth John Odle


    There is probably something wrong with that code, then. Check with Google to make sure you have the right one.



    Add the search code Google gives you to a Plain Text/HTML widget and add the block to your sidebar. Then create a blank page and select HTML editor, then paste the search page code which Google gives.

    I’ve tried Google search for my site. But, the built-in WordPress search functionality is better than Google search. The only excuse to use Google Custom Search is “Ads”!

Viewing 5 posts - 1 through 5 (of 5 total)

  • You must be logged in to reply to this topic.