ThemeShaper Forums » Thematic

[closed]

[HOW TO] Replace WordPress Search with Google Custom Search in Thematic

(3 posts)
  • Started 2 years ago by wlanni
  • Latest reply from gluca
  • This topic is not a support question
  1. wlanni
    Member

    Hello peoples!

    I've mucked with WordPress' search before, and I always feel like I'm fighting a battle not worth fighting. Its results are kinda crappy, relevance is non-existant... all in all pretty much a waste of my time.

    I figured I'd let Google do the hard work for me, since they specialize in Search, right? But how to do that easily in Thematic, without having to go and completely rewrite search forms, search results, or even worse... download outdated plugins that refer to outdated Google Search techniques like iFrames!?

    As of Dec, 2012, the following information should hold true. Hopefully Google doesn't change things up any time soon, and if they do, well, hopefully I'll get the emails to come update this.

    First off, refer to this wonderful web page that describes setting up google custom search and how to set up all the code on the Google Side.

    You'll return back here once you have the google code that the author of that page instructs you to cut and paste into the contents of searchform.php and search.php. We're going to do it differently, using hooks'n'filters and your child theme functions.php.

    OK... I assume you're back, and you got a page of from Google with a couple fields of code on it.

    What you'll do now is open your functions.php file in your child theme that you're developing out of rather than altering the default Thematic templates (Right? RIGHT?!)

    In your Functions.php, you're first going to create a filter to rewrite searchform php. You're going to copy the blurb of google code from the top field, and insert into a custom function that looks something like the following:

    function childtheme_search_form() {
    ?>
    
    INSERT YOUR CODE HERE (and replace this text)
    
    <?php
    }
    add_filter('thematic_search_form', 'childtheme_search_form');

    The default look and feel of the wordpress search won't change, but the functionality behind it will.

    Next you'll make use of the really handy childtheme_override function that's already built into Thematic, for the Search Loop. You'll insert the block of code from the second google field where I describe:

    function childtheme_override_search_loop() {
    ?>
    
    INSERT YOUR CODE HERE (and remove this line).
    
    <?php
    }

    Lastly, you might want to customize some of the look and feel of the google elements. You can either sign up for their paid-for search partnership, OR you can go back and download the .css file from the theme you chose when you were setting up your search. It will be the 2nd to last link at the bottom of the "Get Code" page, and it should say something like

    You can customize the look and feel even more or extend the functionality of the Custom Search element by:

  2. Downloading the CSS source file.
  3. I copied the contents of that css file into its own search.css file that I plopped into a "layouts" directory in my childtheme. I then used an @import in the style.css to have it automatically included. I then proceeded to restyle the theme I chose to match the site I built. Note: you have to use !important after any style elements you update, as the google css is pulled in after your style sheet.

    And that's it. The site I just finished about 30 minutes ago (so the site hasn't been indexed and there are no results showing yet, as of Dec. 14 2012, 3:40am) is Pacific Standard Time Art and Performance Festival.

    All right, hope that helps!

    Posted 2 years ago #
  4. gluca
    Member

    I follow step by step your recipe (thx!) but my search box is showing a sad "loading"
    could you take a look at my blog www.minimarketing.it ("cerca")
    I tried several workaround, as to disable js plugin, but nothing seems to work :(
    script seems ok!

    Posted 2 years ago #
  5. gluca
    Member

    Now box is appearing. but search still doesn't work. it seems to recall home page simply http://www.minimarketing.it/?q=test
    No search at all :(

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.