Uncategorized

WordPress Search Bookmarklet

As part of the blog transition I took a spin at creating a new tool that would create a WordPress search bookmarklet, more or less a quick re-do of the one I originally created for MovableType.

It is even easier to construct for WordPress, as all you need to know is the base URL for the WP blog- the WordPress search URL is very simple, merely the URL plus a value to pass for the key word search:

http://www....WP-blog-url/index.php?s=blog

making it really easy to create permanent bookmarks for blog searches, e.g., my spam roach collection:

http://cogdogblog.com/index.php?s=spam+roach.

Hmmm, this is a sneaky way to make new pseudo categories.

Anyhow, another cheap WP hack is the new Make a WordPress Search Bookmarklet– it allows you to create a browser bar tool that can either do a search of a particular WP blog using any text highlighted in a page, or it will pop up an input box for entering the search terms.

This way you can search any WordPress Blog w/o having to go to the blog itself and use the search form.

This would have been easier, except I found out testing that recent versions of Safari and Firefox treat the JavaScript getSelection() function differently, whereas before it was always a string, now it is an object, but apparently methods of the result behave differently. The fix, with help from Joe Maller’s blog, is to contcatenate the results with an empty string, thus you end of with a string to test with again.

So any old bookamrket that relied on:

t=getSelection(); if (!t) ...

is broken as on some browsers the results when there is no selection range from “undefined” to “” to ???. The easy fix was to adjust the code to force conversion to a string:

t=getSelection()+''; if (!t) ...

so the if() statement is forced to be testing a tring.

If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for CogDog The Blog
An early 90s builder of web stuff and blogging Alan Levine barks at CogDogBlog.com on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person. And he is 100% into the Fediverse (or tells himself so) Tooting as @cogdog@cosocial.ca