WordPress.org

Ready to get started?Download WordPress

Forums

Google Hilite Hack/Mod (38 posts)

  1. Ryan Boren
    WordPress Dev
    Posted 10 years ago #

    This highlights search terms in your post contents for visitors coming to your site through Google, Lycos, and Yahoo. Other engines are easily added. It will also highlight searches driven by your WordPress search box.
    See here:
    http://boren.nu/testbed/wp-hilite.phps
    Add this as wp-hilite.php to your installation root.
    Now, add this to my-hacks.php:
    require_once(ABSPATH . 'wp-hilite.php');
    add_filter('the_content', 'hilite');
    Here's what mine looks like:
    http://boren.nu/testbed/my-hacks.phps
    Now, add the following to your css:
    .hilite { background-color: #FF9; }
    Change the color to suit.
    This adds extra processing time for every post displayed, so you could see longer load times. Most of the regular expressions are anchored, so it shouldn't be too slow.
    Anyway, just a quick hack^Wmod I threw together.

  2. Laughinglizard
    Member
    Posted 10 years ago #

    Thats very sweet! We were just talking about this on IRC. The load time excesses are almost negligible.

  3. Alex King
    Member
    Posted 10 years ago #

    That is pretty slick, thanks!

  4. davidchait
    Member
    Posted 10 years ago #

    Nice and simple!
    =d

  5. OperaManiac
    Member
    Posted 10 years ago #

    may i suggest integration with the original installation?

  6. Lester Chan
    Member
    Posted 10 years ago #

    LEET

  7. Ryan Boren
    WordPress Dev
    Posted 10 years ago #

    Matt is adding this to CVS. So, you won't need to require wp-hilite.php since the code will be in functions.php. You will still need to put the add_filter(...) line in your hacks file. This will not be turned on by default.

  8. Alex King
    Member
    Posted 10 years ago #

    I found a little problem with this, when using nice URLs, the category links are fooling the "hilite" code. For me, it was highlighting whitespace. I added this on line 95:
    if (!empty($term) && $term != ' ') { (closing on line 101) and that fixed it.

  9. Lester Chan
    Member
    Posted 10 years ago #

    Okie, i have copy the codes from the initial source. The funtions.php did not include wordpress search word highlighting

  10. Ryan Boren
    WordPress Dev
    Posted 10 years ago #

    The version in CVS is an older one that only has Google. Wait for an update.

  11. Lester Chan
    Member
    Posted 10 years ago #

    oh thanks rboren

  12. Matt Mullenweg
    Troublemaker
    Posted 10 years ago #

    Fix applied to CVS.

  13. OperaManiac
    Member
    Posted 10 years ago #

    goodie, in the 11th Jan nightly?

  14. Lester Chan
    Member
    Posted 10 years ago #

    erm i got a question here

    if ( is_referer_search_engine($engine) && !empty($term) && $term != ' ') {

    I think $term will always be empty because $term is only define in the foreach loop.

  15. Alex King
    Member
    Posted 10 years ago #

    Gamerz - correct, the fix in CVS won't work. I'm updating it.

  16. Anonymous
    Unregistered
    Posted 10 years ago #

    @alex: =D

  17. Lester Chan
    Member
    Posted 10 years ago #

    ops, it was me, forgot to login

  18. Nick Momrik
    Member
    Posted 10 years ago #

    Seems to even work on the excerpt now! :-)

  19. seriocomic
    Member
    Posted 10 years ago #

    I have added the latest CVS versions of funtions.php, wp-blog-header.php and added the line 'add_filter('the_content', 'hilite');' to my-hacks.php (which is activated) but there is no span tags on the search result...
    what have I forgotten?

  20. Lester Chan
    Member
    Posted 10 years ago #

    the hilite is buggy, sometimes it highlights sometimes it don't.

  21. seriocomic
    Member
    Posted 10 years ago #

    Yes, I noticed that it didn't work on the result of the search, but if I clicked on any internal link, and the searched-for term was in that link-post, then the highlighting worked (does that make any sense??).
    Considering that my site is blocked from SE robots, I only want the internal (wordpress) search to work.
    I wonder if the add_filter is being called at the right time?

  22. davidchait
    Member
    Posted 10 years ago #

    I've had no problems with the original posted by rboren at the start of this thread. It's up working on http://www.chait.net, whether coming in through a search engine, or searching locally, just works.
    Actually, the only problem I had was that I need it to run earlier -- my own hacks to post-process the content block are now 'built-in' features, and so my amazon inline-blocks in reviews and articles are having words in the titles hilited! It's 'sorta cool', but screws up sizing/positioning of things a bit! ;)
    -d

  23. seriocomic
    Member
    Posted 10 years ago #

    ...and now it works fine...
    http://www.seriocomic.com

  24. Nick Momrik
    Member
    Posted 10 years ago #

    Any ideas on how to get the comment text highlighted as well? Google results often find words in the comments and it would be cool to be able to highlite them as well. Would there be a way to allow the SPAN tag to be added to comments by WP, without opening it up to allow comment authors to use it?

  25. Nick Momrik
    Member
    Posted 10 years ago #

    *bump*

  26. Anonymous
    Unregistered
    Posted 10 years ago #

    I can`t download the hack from "http://boren.nu/testbed/wp-hilite.phps". Where can i find it?
    Thanks

  27. Lester Chan
    Member
    Posted 10 years ago #

    it is now incoporated in WordPress

  28. Anonymous
    Unregistered
    Posted 10 years ago #

    thanks!!

  29. Anonymous
    Unregistered
    Posted 10 years ago #

    don't seems to work in my local instalation. When i search in my weblog, ni Hilited words appear. Do i need any configuration?

  30. OperaManiac
    Member
    Posted 10 years ago #

    yup the thing is buggy with my installation too.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.