Support » Plugin: Relevanssi - A Better Search » Search hit highlighting messes URL links

  • Resolved Andrzej


    It appears that search terms that appear in an ‘href’ URL are replaced by the HTML ‘strong’ tag making the URL dis-functional. Has anyone else has seen this issue or could it be that my Relevanssi settings need tweaking. I don’t see an option to disable URL highlighting.

    In my case, a page has a URL link where the link name is also the URL.

    Thanks for all suggestions.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I have exactly the same problem –

    I’ve just started using Relevanssi Search and it’s great. I will almost certainly upgrade to the paid for version. However, I have a bug to fix first.

    When I configure search to highlight query terms, if any graphic on a relevant page contains the search query term in its name it does not display. For example, on my blog I search for TOC, and there is 1 page in the results, this page contains a graphic called TOC.png which no longer displays.

    This seems to be because Relevanssi changes the name of the graphic in order to try and highlight it. The graphic is here –

    But on the search results page the link is changed to a none existent –'background-color:%20#ffaf75'>TOC</span&gt;.png

    I’ve replicated this fault on other pages, and it only seems to affect any image with a name containing the searched for term.

    After some poking around in the Relevanssi excerpts-highlights.php file, I found a temporary workaround.

    – just after line 339: get_option(‘relevanssi_word_boundaries’, ‘on’)…
    – add: $word_boundaries = false;

    Alternately, in the settings area, uncheck: Uncheck this if you use non-ASCII characters. I haven’t tried this setting but the source code shows that this option controls ‘word_boundaries’, which may also affect the image link modification.

    This may have something to do with ‘Create custom search result snippets’ option. Do you have that checked? It makes for nicer search results but can also mess things up if you have complex template files.

    If you don’t want your image attachments turning up, you can uncheck ‘attachment’ from the ‘indexing options’. Or use the Exclusions section to target individual attachments.

    I wouldn’t rush to mess with the plugin files themselves… what if there is an update?

    Try using filters instead, check out this example of search filtering from the Relevanssi User Manual.

    I made a filter to to return only attachments which are Word Docs, excluding all other attachments:

    add_filter('relevanssi_hits_filter', 'exclude_attachments');
    function exclude_attachments($hits) {
    	$filtered = array();
    	foreach ($hits[0] as $hit) {
    		if($hit->post_type == 'attachment')
    			//Only keep attachments that are Word Documents
    			if ($hit->post_mime_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
    				array_push($filtered, $hit);
    		//Keep all results that are not attachments
    		else {
    			array_push($filtered, $hit);
    	$hits[0] = $filtered;
    	return $hits;
    Plugin Author Mikko Saari


    This was just fixed in version 3.1.6.

    That’s great news thanks 🙂


    Thank you so much for all the pathes and refinements. I have verified that the bold link issue has been resolved and everything is working nicely.


Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Search hit highlighting messes URL links’ is closed to new replies.