There is most likely a problem with escaping HTML in your code. You might be doing something like this:
echo esc_html("Search Results for: <span>search_word</span>");
Instead, use printf
or only wrap your search word with esc_html()
:
printf('Search Results for: <span>%s</span>', esc_html( $search_word ) );
Update
The search results are rendered by search.php
, most of the times (If it exists, and you don't have rewrite rules and template redirects, etc.)
But first, right click on the header that is having problem, and click Inspect Element
. The developer console will open, and the header will be highlighted. Take a look at below screenshot that belongs to the header of this question:
Now, you know the general structure that is surrounding your header. You can look for this pattern in your search.php
file.
Update 2
It appears that you are using the free Primer theme from the WordPress's theme repository.
After digging for a while, after a chain of Tom & Jerry"Tom & Jerry styled" chase of functions declared randomly all across the templates, I've found the source of your issue. The issue is coming from line 47 of /inc/helpers.php
:
$title = sprintf(
/* translators: search term */
esc_html__( 'Search Results for: %s', 'primer' ),
sprintf(
'<span>%s</span>',
get_search_query()
)
);
Which is what I was expecting. To solve the issue, simply remove the <span>
and </span>
that are wrapping the search query. You can solve this without removing the spans, but it requires a couple of more files to be chain edited. Removing it is not a big deal though.
However, you can use a child theme to do this.