• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Customizing search results page for use with Relevanssi

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Customizing search results page for use with Relevanssi

This topic is: resolved
  • This topic has 24 replies, 3 voices, and was last updated 12 years, 4 months ago by Guter.
Viewing 20 posts - 1 through 20 (of 25 total)
1 2 →
  • Author
    Posts
  • December 30, 2012 at 10:43 am #8384
    lostintime
    Member

    To make searching a better user experience I am using the plugin Relevanssi on my blog. Now I would like to implement Google-style “did you mean” suggestions for those situations where no results are found. The plugin author suggests adding the following line of code to the search results page in order to get that extra functionality:

    <?php if (function_exists('relevanssi_didyoumean')) { relevanssi_didyoumean(get_search_query(), "Did you mean: ", "", 5); }?>

    My question is: Where exactly should this piece of code go and how do I go about adding it? My theme (Streamline) does not have its own search.php file and search.php under genesis/lib/functions/ seems to deal only with the search form, not with the results page.

    Any help is greatly appreciated.

    December 30, 2012 at 12:12 pm #8402
    Bill Murray
    Member

    You can add the code in the attached link to your child theme's functions.php.  See the inline documentation in the code to add it just to your search page.  To do that, get the page ID of your search results page (you can mouse over the URL in the WP dashboard and note the ID in the URL) and replace '1234' with your page ID.

    http://wpp.im/9

    Always be sure to have a good backup of your functions.php and the ability to put back a good copy to your server (such as with FTP) prior to making any changes, because even a small typo can break your site.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    December 30, 2012 at 1:22 pm #8428
    lostintime
    Member

    That looks great Bill. Thanks! Will try it and let you know how it goes.

    Just a thought: Could I replace

    if ( is_page('1234') ) {

    with

    if ( is_search() ) {

    ?

    December 30, 2012 at 4:26 pm #8454
    Bill Murray
    Member

    Good thought. That change should work too. Give them both a try and post back with your results.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    December 31, 2012 at 12:25 pm #8615
    lostintime
    Member

    It works – you're brilliant Bill 🙂

    Now I only have to figure out how to style the output, because the resulting string gets displayed at the top left corner of the browser window instead of *inside" the search results page, where I want it to appear.

    Any suggestions on that?

    Happy New Year's Eve!

    December 31, 2012 at 1:36 pm #8620
    Bill Murray
    Member

    Please up your standards for brilliance. 🙂

    Have a link to your site? I can check what CSS Relevannsi is outputing with its function, which is quicker than looking in the code.

    Btw, did the is_search() work?

    Same to you.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    December 31, 2012 at 2:20 pm #8623
    lostintime
    Member

    Yes, is_search() worked fine, which makes the function a bit more generic.

    Here's the link to my site: http://www.buurtaal.de/blog/

    It's in German. I hope that doesn't scare you 😉 The search box is in the sidebar, there where it says "SUCHEN AUF BUURTAAL"

    I used the search term "olibollen" . That should give you "Did you mean: oliebollen" in the left top corner. (The free version of Relevanssi which I am using bases the suggestions on logged queries. Since I only started usin the plugin yesterday there is currently very little data.)

    Thanks again for your help, it's very much appreciated.

    December 31, 2012 at 5:27 pm #8639
    Bill Murray
    Member

    I took a look and updated the code on my link. Grab an updated copy and it should fix the problem you observed.

    The bad placement was because I wasn't sure where that function would do its work, so I loaded it in a less than ideal place. I've now set it to load in a more ideal place, but we'll have to see if the change suits your needs.

    Post back with the results.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    January 1, 2013 at 4:20 am #8698
    lostintime
    Member

    You're my coding hero Bill 😉

    I ended up changing the hook to genesis_after_content because using genesis_before_content displayed the result in the sidebar.

    Thank you so much for pointing me in the right direction.

    January 1, 2013 at 8:37 am #8722
    Bill Murray
    Member

    Hmmm...after thinking about this more, the genesis_after_post_content hook might be even better. genesis_after_content isn't quite right, which is why the text is so far to the left.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    January 1, 2013 at 9:26 am #8725
    lostintime
    Member

    I tried that, but unfortunately genesis_after_post_content made the string disappear .... Could that be because the search results are not displayed in a post?

    Using genesis_after_content seems to bring the best result – even though it isn't pretty because of the missing left margin.

    Would it be possible to style the output using css? Or would you consider that a hack?

    January 1, 2013 at 10:06 am #8734
    Bill Murray
    Member

    Before we go the CSS route, let's try this:

    add_action('genesis_after_post_content', 'wpp_relevanssi_did_you_mean', 5);


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    January 1, 2013 at 10:17 am #8736
    lostintime
    Member

    Bummer, no joy unfortunately. The string doesn't display anywhere on the page.

    January 1, 2013 at 10:34 am #8737
    Bill Murray
    Member

    Let's not give up yet...

    Does Relevanssi create a page for search results? Can you try the code in my last example using the is_page() with the page ID? I'm wondering if the is_search() thing is breaking it.

    The addition of the priority (the 5 parameter) should have fixed the "not displaying" issue.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    January 1, 2013 at 12:40 pm #8764
    lostintime
    Member

    The thing is that I there doesn't seem to be a separate page for displaying the search results. At least there's nothing in the Streamline backend. That's what's preventing me from using is_page() with the page ID.

    January 1, 2013 at 1:24 pm #8787
    Bill Murray
    Member

    I updated the code on the link. Let's see if this gets closer. I added a priority because right now this is getting added after the sidebar. Then, I gave the strings some CSS based on Relevanssi's documentation.

    I gave it an ID of didyoumean, so you'll need to add something like this to your child theme's style sheet:

    /* Relevanssi search result when nothing found */
    #didyoumean { margin: 0 0 10px; padding: 0 30px; }
    

    That ought to make it line up with the other content. Adjust to suit your taste. Keep your fingers crossed 🙂


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    January 1, 2013 at 3:14 pm #8816
    lostintime
    Member

    Wow, this is interesting. The updated code made the result appear at the top of the sidebar again. When I changed genesis_after_content back to genesis_before_content it went back into the post content area. With the css in place it now looks perfect.

    A big thanks for all your time and advice!

    January 1, 2013 at 5:58 pm #8853
    Bill Murray
    Member

    Glad it works. It looks good.

    I think the priority caused the genesis_after_content not to work. The default priority is 10, and lower numbers mean higher execution priority, so maybe 5 was too low. You can delete the priority altogether, since it's optional. I don't understand the on-screen text, but if the order isn't to your liking, you can try going back to the after content hook and upping the priority. That might put this text after the content, which I suspect says that the string wasn't found. If you use use a tool like Firebug or right click on an element in Chrome and inspect it, you can see where it puts that ID, and the goal is to get it after the content but before the sidebar. The CSS won't change.


    Web: https://wpperform.com or Twitter: @wpperform

    We do managed WordPress hosting.

    January 2, 2013 at 7:07 am #8927
    lostintime
    Member

    Thanks for your thoughts! Will give it a try.

    January 2, 2013 at 7:21 am #8930
    lostintime
    Member

    Yep, I upped to priority to 10, changed the hook back to genesis_after_content and now everything is the way I want it to look.

    I can't thank you enough Bill for all your hand holding through this process.

  • Author
    Posts
Viewing 20 posts - 1 through 20 (of 25 total)
1 2 →
  • The topic ‘Customizing search results page for use with Relevanssi’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble