Relevanssi and Modernize

Modernize is a neat Premium theme that has a problem with Relevanssi. Relevanssi highlighting can cause problems on Modernize search results pages, with results getting wrong background color.

This problem is caused by the way Modernize truncates excerpts to certain length, set in the Modernize settings. It doesn’t care about HTML tags, so Modernize may cut the excerpt in the middle of a HTML tag inserted by Relevanssi, causing the markup to break.

Add this code to the theme functions.php to make highlighting work in Modernize:

add_filter('pre_option_'.THEME_SHORT_NAME.'_search_archive_num_excerpt', 'relevanssi_modernize_fix');
function relevanssi_modernize_fix($value) {
	if (is_search()) return 1000;
	return $value;

This makes the excerpt length 1000 characters on search results pages. If you use longer excerpts, adjust the value: it needs to be higher than you ever need (so make it 1000000 to make sure: the actual length of the excerpt is defined in the Relevanssi settings).