Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Rachellesays
This works great but how do you highlight the search term in the excerpt and not just the title?
Hej, thank you very much for this very helpful piece of code. Is there a way to exclude links? The code as is breaks many of the “more”-links on my site.
Thanks for the suggestion. We will try to update the article with more detailed instructions.
Meanwhile, you will need to edit the /template-parts/content-search.php template. If your theme does not have it, then you can create it and then reference it in your search.php template.
This doesn’t even come close to working. All it does is display the title of the page the search term is found on. The terms themselves aren’t wrapped in any tags whatsoever.
Nice tutorial. And for those wo want to make some highlight with colors they must define their css class as div.highlight
and replace the code with
And that`s alll. Thanks and have fun.
Syed Balkhi says
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Rachelle says
This works great but how do you highlight the search term in the excerpt and not just the title?
Imme says
Hej, thank you very much for this very helpful piece of code. Is there a way to exclude links? The code as is breaks many of the “more”-links on my site.
Vernon Fowler says
Any chance you can update this neat tutorial for modern themes such as Twenty Seventeen where instead of title() in the loop, the loop goes through:
1-click Use in WordPress
I’m comfortable with replacing
1-click Use in WordPress
with HTML5
1-click Use in WordPress
and the relevant CSS.
Or will we need a different approach in themes using get_template_part ?
WPBeginner Support says
Hey Vernon,
Thanks for the suggestion. We will try to update the article with more detailed instructions.
Meanwhile, you will need to edit the /template-parts/content-search.php template. If your theme does not have it, then you can create it and then reference it in your search.php template.
管理者
Vernon Fowler says
That’s working. Thank you.
Can we do the same for the_content as for the the_title or do we need a different approach?
Wayan Cenik says
Thanks a lot for the code, is work perfectly
I just the code at function, and done, is work
Marlene says
Hi
I can´t find on my site. I have this:
How can I change someting in that?
Thanks
Marlene
Steph says
There is no “” in my search.php file..
—————————–
Mine looks like this:
“”
WPBeginner Support says
Seems like you wanted to paste code and it stripped out. Please wrap your code around [php] [/php] tags
管理者
Mahesh says
Thanks @michael
Steve says
This doesn’t even come close to working. All it does is display the title of the page the search term is found on. The terms themselves aren’t wrapped in any tags whatsoever.
nate says
Actually, it works perfectly. I don’t think you know what you are doing.
Jason says
Thanks! Works like a charm!
Chris says
You should add a little example image on every tutorial, that would be more understandable (:
DauAnunturi says
Nice tutorial. And for those wo want to make some highlight with colors they must define their css class as div.highlight
and replace the code with
And that`s alll. Thanks and have fun.
Nina says
Very helpful tutorial, will use it later on![:)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)
Thanks for sharing!