Google Hilite Plugin for TextPattern

Nov 19, 09:55 AM by Jonathan Howard

I’ve updated the google_hilite mod for TextPattern by Dean Allen. I’ve gone ahead and changed it into a plugin, so rather than uploading a php file and inserting php into your pages, you now just insert tags to get the same functionality.

It’s essentially the same code with a plugin wrapper.

To use the hiliting feature, put <txp:myt_google_hilite /> right after your <body> anywhere in your <head> tag. To add a message noting that google results will be hilited, place <txp:myt_google_welcome /> wherever you’d like to place that message. That message can be modified in the plugin.

-You also need to add .hilite { background-color: [color of your choice]; } to your style sheet.-

v0.2:

There is a new attribute on the <txp:myt_google_hilite /> tag. You can add the color=”#[hex value]” or color=”[text color like yellow or white]” attribute to define the hilite color. If no color is defined, it uses the color “#FFFF99”.

v0.3:

There is another new attribute on the <txp:myt_google_hilite /> tag. You can add the class=”[class]” attribute to define the class for the hilite color to avoid interfering with your own styles. If no class is defined, it uses the class “hilite”.

There is a new attribute on the <txp:myt_google_welcome /> tag. You can add the text=”[text]” attribute to set the text that will be used to welcome Google users. If the text attribute is omitted, it defaults to “[Google search terms are highlighted]”.

Many thanks to Andy Warwick for all his help debugging and suggesting features!

Download the plugin here

  1. And I notice that the tags in the help section are ‘disappearing’, so that it reads:

    ‘Just add to your page under . If you wish to welcome google users, add .’

    Andy Warwick · Nov 19, 10:38 AM · #

  2. Looks like a good plugin, but get the following error when I install it:

    “ag_error -> Notice: Use of undefined constant HTTP_REFERER – assumed ‘HTTP_REFERER’ on line 60
    textpattern/lib/txplib_misc.php(512) : eval()‘d code:60 google_welcome()
    textpattern/lib/txplib_misc.php(512) : eval()‘d code:7 google_welcome()
    textpattern/publish.php:958 myt_google_welcome()
    processtags()
    textpattern/publish.php:917 preg_replace_callback()
    textpattern/publish/taghandlers.php:1785 parse()
    textpattern/publish.php:958 body()
    processtags()
    textpattern/publish.php:917 preg_replace_callback()
    textpattern/publish.php:777 parse()”

    Andy Warwick · Nov 19, 10:39 AM · #

  3. I wasn’t getting that error on my site, so I can’t test it. I changed it so it now uses $_SERVER[‘HTTP_REFERER’] instead of $_SERVER[HTTP_REFERER]. Could you or someone else test it and see if it works?

    I was getting the help page problem, that should be fixed now.

    Jonathan Howard · Nov 19, 11:12 AM · #

  4. That appears to have fixed it when just visiting the page directly; it’s a work-in-progress, so I can’t check if it is 100% when coming in via Google, but adding the quotes certainly stopped the error message appearing.

    I suggest you set PHP so that it shows /all/ errors when developing, as that will show errors like that. See and E_NOTICE.

    Andy Warwick · Nov 19, 11:18 AM · #

Commenting is closed for this article.