Joomla’s Search Results Have <span class=”highlight”> – How to Fix!

A client of ours emailed us this morning and told us that the search functionality on their website is acting funny, and asked us to take a look. So, we tested the search by entering a term relevant to the client’s business, and we noticed that many titles in the search articles had something like <span class=”highlight”> in them.

A quick research about this issue revealed that this was a Joomla core problem, and fixing it consisted of changing the following line in the function highlight (which is located in the view.html.php file, which, in turn, is located in the components/com_search/views/search) folder from:

$highlighterLen = strlen($hl1 . $hl2);


$highlighterLen = '';

Doing the above nearly fixed the problem, because we were still seeing “&#16” at the end of most titles. Also, we were not convinced that this so obvious problem exists in the Joomla core, and nobody stepped up and resolved it, so, we investigated the issue further.

Our Sherlock Holmes investigation finally led us to the client’s template, specifically the file default_results.php, which is located in the templates/[joomla-template]/warp/systems/joomla/layouts/com_search/search folder. The aforementioned file, which is the search results listing override in a YooTheme powered template, contained the following line:

<h1 class="title"><?php echo $this->escape($result->title); ?></h1>

The above line contained one method, which was the essence of the problem, and it was $this->escape. In short, this method was trying to escape what was already escaped by Joomla. Modifying the above line to this one fixed the problem:

<h1 class="title"><?php echo $result->title; ?></h1>

So, the next time you are seeing any weird HTML code in your search results, don’t immediately blame Joomla for it (and, most importantly, do not change any core files to fix the problem) as it might be your template trying to re-escape content. Don’t forget, we’re always a call or an email away if you need help in fixing the problem, oh, and our fees are super affordable!

One Response to “Joomla’s Search Results Have <span class=”highlight”> – How to Fix!”
  1. Comment by gourou — June 6, 2020 @ 5:06 am

    Hi thanks for your article – it’s the best way to fix this problem.

    Just 1 thing as the result of the function $highlighterLen must be numeric it should be better to put 0 instead ”

    $highlighterLen = 0;

    Otherwise, you will get the following error:

    mod_fcgid: stderr: PHP Warning: A non-numeric value encountered in

Leave a comment