Skip to main contentSkip to footer

In some cases, Relevanssi requires modifications to the search result template for the search results to work properly (in particular when using Relevanssi Premium to search user profiles and taxonomy terms). Adjusting the templates is really simple, usually just changing the_permalink() to echo relevanssi_get_permalink() is enough, but framework themes like Genesis make small changes like these more complicated.

Sarah Moyer took the effort to figure out how to make the necessary changes in Genesis. First, in order to get the correct permalink in the post title, add this code to your site:

// Modify content to add Featured Images and Relevanssi permalink
add_action( 'genesis_entry_content', 'child_do_post_excerpt', 1 );
function child_do_post_excerpt() {
    if (is_search()) {
        remove_all_actions( 'genesis_entry_content' );

	// Get featured image if page or post
	the_post_thumbnail( 'medium', array( 'class' => 'alignright' ) );

	// Uncomment the following lines to get featured image if WooCommerce product category - this doesn't work if you don't use WooCommerce
	//global $post;
	//$thumbnail_id = get_woocommerce_term_meta( $post->term_id, 'thumbnail_id', true );
	//echo wp_get_attachment_image( $thumbnail_id, 'medium', '', array( 'class' => 'alignright' ) );

	// Get excerpt rather than the_content() so Relevanssi can grab a snippet and highlight search terms
	the_excerpt();

	// Get 'Read More' link with Relevanssi permalink
	if ( function_exists( 'relevanssi_get_permalink' ) ) {
		echo '<a class="read-more-link" href="' . esc_url( relevanssi_get_permalink() ) . '">View more »</a>';
	}
    }
}

Then, for excerpts:

// Modify content to add Featured Images and Relevanssi permalink
add_action( 'genesis_entry_content', 'child_do_post_excerpt', 1 );
function child_do_post_excerpt() {
    if ( is_search() ) {
        remove_all_actions( 'genesis_entry_content' );
 
		// Get featured image if page or post
		the_post_thumbnail( 'medium', array( 'class' => 'alignright' ) );
 
        // Uncomment the following lines to get featured image if WooCommerce product category - this doesn't work if you don't use WooCommerce
        //global $post;
        //$thumbnail_id = get_woocommerce_term_meta( $post->term_id, 'thumbnail_id', true );
        //echo wp_get_attachment_image( $thumbnail_id, 'medium', '', array( 'class' => 'alignright' ) );

        // Get excerpt rather than the_content() so Relevanssi can grab a snippet and highlight search terms
        the_excerpt();
 
		// Get 'Read More' link with Relevanssi permalink
		if ( function_exists( 'relevanssi_get_permalink' ) ) {
			echo '<a class="read-more-link" href="' . esc_url( relevanssi_get_permalink() ) . '">View more »</a>';
		}
    }
}

This plugin may also be useful: Iron Code Improve Genesis Theme Search.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Different fuzzy search setting on different searches

…for example, “none” when you’re doing an employee/department search. For example, you can set a global variable before the relevanssi_do_query(), like this: global $relevanssi_disable_fuzzy; $relevanssi_disable_fuzzy = true; relevanssi_do_query( $args ); Then use that global variable as a trigger: add_filter( ‘pre_option_relevanssi_fuzzy’, ‘rlv_disable_fuzzy’ ); function rlv_disable_fuzzy( $value ) { global $relevanssi_disable_fuzzy; if……it on the employees/department search? Yes, you can, but it takes some hacking. Since Relevanssi has just one setting for the fuzzy search, you need to change it on the fly for one of the searches. It’s probably easier to do with the relevanssi_do_query() search. Relevanssi reads the fuzzy search……setting from the relevanssi_fuzzy option. WordPress provides you with pre_option_relevanssi_fuzzy filter you can use to change the value. The values are “always” and “sometimes”, and everything else counts as none. So, set the setting to always from Relevanssi settings, and then add a filter function that sets the value to,…

Attachment file content cannot be saved

…databases used utf8 characters. Since 4.2, the collations have used utf8mb4 characters. It’s not unusual that PDF files contain characters that WordPress cannot save in a database table with a utf8 collation. To fix this, you need to change the database collation. You can make this change if you have……some reason, that function is not accepting the custom field data. In these cases, the first thing to check is the database collation for the meta_value field in the wp_postmeta database table. The document may contain characters your database table cannot accept. Before WordPress 4.2, the default collation for the…

Search shortcode

Relevanssi adds a shortcode to help making links to search results. That way users can easily find more information about a given subject from your blog. The syntax is simple: John Doe This will make the text John Doe a link to search results for John Doe. In case you…

Related Posts:

Comment Section:

13 Comments. Leave new

  • Kevin Donnigan
    December 14, 2017 7:03 pm

    Thank you SO much for this, both of you. Total time saver.

    Reply
  • And if one does not want to use “excerpts” instead of “content” (since this may have consequences for other things on a website), Sridhar Katakam has provided a piece that works fine for showing search results as excerpts when inserted in the theme’s functions.php :
    https://gist.github.com/srikat/6912382
    I have just applied it to a site using Modern Studio Pro theme, and it is working really fine!

    Reply
  • Bought Relevanssi Permanent today (after reading the promise that PDF support is coming soon as part of the plugin!). I have all my WP sites using Genesis, I came across the same issue. The first part of the code worked fine in my theme’s functions.php. But the second part of the code just made all my pages blank.
    Looking for an answer, I found the following solution while scouting the Web. Very simple, and it works fine:
    https://www.clearbusiness.com/using-relevanssi-with-genesis-studio-wordpress-theme-framework/
    I have made the selection from “content” to “extract” for Archives in the Genesis settings for two websites, and instantly excerpts and highlighting have started working, without any need to change anything in code.
    Of course, is somebody really wants to have “content” instead of “extract” as the option for Archives, it won’t work. Otherwise, it is a very easy solution.

    Reply
  • I’m running WP 4.4.1, Genesis 2.2.6 and Child theme “magazine”. I’ve tried this code and also the instructions regarding using genesis “post except”. Can’t get Relevanssi to work at all, I only see the default search results. Any more thoughts?

    Reply
  • How can I use these scripts to add featured image in my search results?Can a free version do?Looking for an answer……

    Reply
    • Put the second code snippet to your theme functions.php, that should get you featured images in search results.

      Reply
      • Nooooo!I did what what you told me to and my website now is completely white and blank!!!!Can you tell me how to find “theme functions.php” in my FTP?So I can save my website!Thanks

        Reply
        • The functions.php file is in your theme folder, which is probably in /wp-content/themes/yourtheme/functions.php.

          Using WordPress code editors is not a good idea unless your familiar with PHP code, as even a single typo or pasting the code to the wrong place will bring your site down like this.

          Reply
          • Thanks a lot!I just bring my website back!So Is there a safer way to let the Featured Images appear in the search results?

          • That’s pretty much the only way. To make it safer, have a PHP developer add the code to your site. That should take an experienced developer about five minutes.

          • Thanks,I will be more careful next time!

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed