WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Google Custom Search in WordPress (21 posts)

  1. tamar
    Member
    Posted 6 years ago #

    I'm trying to apply the Google Custom Search Engine in my WordPress installation, and the results page show up blank.

    I followed two different kind of instructions but both failed on me.

    The first one, explained here, describes how you set up a page (Write > Page) and paste the JavaScript code into the text area (obviously in HTML).

    The second one, explained here, requires you to set up a template page (_search.php) in your theme directory and then create the page using that template.

    Both of those tips were applied at different times. Both of those failed me. My blog is here and you can tell that if you try to perform a search, a blank page shows up.

    That apparently was a big issue for others as well. But it worked for many people, so I'm inclined to think there's some small thing I'm missing here.

    The question is - what?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    I use a Google Custom Search on my blog, but I set it up so long ago that I forgot how I did it. :)

    Looking closer at it, it appears that I created a Page called "search-results" with the necessary javascript code in it. Then I pasted the search box code into a sidebar widget.

    Looking at your code, it would seem to me that your var googleSearchIframeName is set wrong. Try changing it to this:
    var googleSearchIframeName = "results_014170601555854922742:d3x1hsdptlk";

    Might work.

    More to the point though, both bits of code on your page are not the verbatim code from the http://www.google.com/coop/cse/ site. You can't change those, they need to be exactly what Google's site gives you.

  3. tamar
    Member
    Posted 6 years ago #

    Wish I could say that that did it, but it doesn't seem to work :(

    I don't think the issue is in the Google code that they provided to me... I think something in the theme causes blank pages for some and not for others. I really have NO idea though, and it's driving me batty.

  4. nathanrice
    Member
    Posted 6 years ago #

    try asking this in the theme support forum.

  5. tamar
    Member
    Posted 6 years ago #

    I'll give it a try, thanks nathan. Hope the double posting won't tick anyone off. I really don't know for sure if it's a theme problem, but my guess is that if it impacts some people and not others, that would be it.

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    I think something in the theme causes blank pages for some and not for others.

    No, that's not it. I get the blank page too, but I see the javascript code there just fine. This is definitely an issue with the javascript that you are using.

  7. tamar
    Member
    Posted 6 years ago #

    Weird. Unfortunately for me, Google is not correctly filling out the variables in the search box. The code they're providing is generic.

    <!-- Google Search Result Snippet Begins -->
    <div id="cse-search-results"></div>
    <script type="text/javascript">
      var googleSearchIframeName = "cse-search-results";
      var googleSearchFormName = "cse-search-box";
      var googleSearchFrameWidth = 600;
      var googleSearchDomain = "www.google.com";
      var googleSearchPath = "/cse";
    </script>
    <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
    
    <!-- Google Search Result Snippet Ends -->

    I applied your changes (see my search.php file now), but this is way frustrating :(

  8. tamar
    Member
    Posted 6 years ago #

    btw, I tried this, but still, a blank page:

    <!-- Google Search Result Snippet Begins -->
    <div id="results_014170601555854922742:d3x1hsdptlk"></div>
    <script type="text/javascript">
      var googleSearchIframeName = "results_014170601555854922742:d3x1hsdptlk";
      var googleSearchFormName = "searchbox_014170601555854922742:d3x1hsdptlk";
      var googleSearchFrameWidth = 400;
      var googleSearchDomain = "www.google.com";
      var googleSearchPath = "/cse";
    </script>
    <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
    <!-- Google Search Result Snippet Ends -->
  9. tamar
    Member
    Posted 6 years ago #

    Okay, figured it out after spending about 7 hours straight on this PITA.

    Google wasn't generating the code properly. I copied and pasted from another site and modified the variables and it seems to be fine now.

    Yeah, I kind of wish I had a better solution to offer, but this is it. :)

  10. lazyazian
    Member
    Posted 6 years ago #

    Can you post where you got the code? and what vars you modifiied?

    I'm having the same exact issue.

    thanks!

  11. tamar
    Member
    Posted 6 years ago #

    Sorry lazyazian - didn't mean to leave you there hanging.

    Here's the information that I used.

    For the search box:

    <!-- Google CSE Search Box Begins -->
      <form id="searchbox_014170601555854922742:d3x1hsdptlk" action="http://www.techipedia.com/search/">
        <input type="hidden" name="cx" value="014170601555854922742:d3x1hsdptlk" />
        <input type="hidden" name="cof" value="FORID:11" />
        <input name="q" type="text" size="20" />
        <input type="submit" name="sa" value="Search" />
      </form>
    
      <script type="text/javascript" src="http://google.com/coop/cse/brand?form=searchbox_014170601555854922742:d3x1hsdptlk"></script>
    <!-- Google CSE Search Box Ends -->

    On the search page:

    <div id="content_cse">
    <!-- Google Search Result Snippet Begins -->
    <div id="results_014170601555854922742:d3x1hsdptlk"></div>
    <script type="text/javascript">
      var googleSearchIframeName = "results_014170601555854922742:d3x1hsdptlk";
        var googleSearchFormName = "searchbox_014170601555854922742:d3x1hsdptlk";
          var googleSearchFrameWidth = 400;
            var googleSearchDomain = "www.google.com";
          var googleSearchPath = "/cse";
          </script>
          <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
          <!-- Google Search Result Snippet Ends -->
    
    </div>

    You WILL need to fill in the variables yourself -- 014170601555854922742:d3x1hsdptlk is specific to my CSE and won't work. Similarly, my code shows my domain -- edit it for your search page. :)

  12. Mattias Tengblad
    Member
    Posted 5 years ago #

    Good post, thanks!

  13. Anonymous
    Unregistered
    Posted 5 years ago #

    tamar,
    I tried doing what you said and it didn't work. Let me be sure I did what you did to get it work...

    First, you never said which of the 2 methods you did but I assumed you created the _search.php one. Second, you pasted both search box and search results code into the code that that web page's directions, but motified the code so it looked like your most recent post on this forum. You uploaded the file to your wordpress directory.

    Third, you made a blank page and selected the theme for cse. You didn't paste anything into this page?

    I just get a page with the search box that then redirects me to my index.php page. I get no results. =( Let me post my code:

    <?php
    /*
    Template Name: SearchResultsFromCSE
    */
    ?>
    <?php get_header(); ?>
    <div id="content_cse">
    <!-- Google CSE Search Box Begins -->
    <form action="http://beta.slythefox.com/?page_id=104" id="searchbox_3080183218079083:wu4ugre2kz3">
      <div>
      <input type="hidden" name="cx" value="3080183218079083:wu4ugre2kz3" />
        <input type="hidden" name="cof" value="FORID:10" />
        <input type="hidden" name="ie" value="UTF-8" />
        <input type="text" name="q" size="31" />
        <input type="submit" name="sa" value="Search" />
      </div>
    </form>
    <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_3080183218079083:wu4ugre2kz3"></script>
    <!-- Google CSE Search Box Ends -->
    <!-- Google Search Result Snippet Begins -->
    <div id="results_3080183218079083:wu4ugre2kz3"></div>
    <script type="text/javascript">
      var googleSearchIframeName = "results_3080183218079083:wu4ugre2kz3";
      var googleSearchFormName = "search-box_3080183218079083:wu4ugre2kz3";
      var googleSearchFrameWidth = 400;
      var googleSearchDomain = "www.google.com";
      var googleSearchPath = "/cse";
    </script>
    <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
    <!-- Google Search Result Snippet Ends -->
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  14. Anonymous
    Unregistered
    Posted 5 years ago #

    Never mind, I got it working. I created a search.php and pasted the code into it but uploaded the file into my main wp directory, not the theme directory, as some sites suggested. It's all great and no modifying of google code was needed.

  15. TheSooFoo
    Member
    Posted 5 years ago #

    I have tried all of this but am still unable to the Google Custom Search to show any results.

  16. Saijo George
    Member
    Posted 5 years ago #

    WordPress users can actually go I more step and integrate the Adsense Search to the WordPress page itself , so the search looks much more like its a part of the site rather than being redirected to a page by Google.

    Look @ the search on my blog or this image to see what i mean : http://img80.imageshack.us/img80/9720/searchintegrationso7.png

    Tutorial : http://www.saijogeorge.com/2008/10/03/google-adsense-search-integration-in-to-wordpress.html

  17. aleemb
    Member
    Posted 5 years ago #

    Or you could just install the Google custom search plugin.

  18. talgalili
    Member
    Posted 5 years ago #

    Hi aleemb.
    I tried the plugin but I get the error massage:

    Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/humus101/public_html/dancebloggers/wp-content/plugins/GoogleCSE.php on line 13

    I am using WP 2.7
    and PHP 4

    any way to fix it ?

    Thanks

  19. khominh.vi
    Member
    Posted 5 years ago #

    I'm trying it by direct coding. Am using a theme and i think that might be the problem.

    when you choose a url when setting up the custom search make sure that you're doing http://www.yoursite.com/* the '/*' means it'll search all the pages in that domain.

    This is where I get lost. Because of the way wordpress and themes are set up on your host, when you perform the search it's unclear whether or not the pages in that domain actually exist.

    Anyone found a solution yet?

  20. Daniel Craig Jallits
    Member
    Posted 5 years ago #

    http://www.yoursite.com/* has nothing to do with the WordPress side of things. The asterisk (*) is a wildcard, telling Google that anything in the domain is searchable.

    So if I wanted to limit search results just to my blog, and the permalink for my blog is /blog. I would then enter http://www.yoursite.com/blog/*

  21. talgalili
    Member
    Posted 5 years ago #

    BTW, I see there is an explanation on how to do this on:
    http://teamtutorials.com/web-development-tutorials/replace-wordpress-search-with-google-search-box

    I implemented it on:
    http://www.dancebloggers.com
    and it works fine.

Topic Closed

This topic has been closed to new replies.

About this Topic