Highlight and Locate Search Terms

Sometimes we have clients that want to give their users a little extra help in finding the search terms they are looking for.

Here is some basic code you can through in your functions.php file to add highlighting to a text string (in my case that is search term).

Obviously, in order for this to work you will need to setup a $_GET variable, probably attached to the link on your search page. That will look something like this:

You will probably want to also setup a background color for your highlight so it is, you know, highlighted:

Lastly, you can also move the user to the first instance of this search term like so:

Add Custom Fields to Woo Variations

Sometimes each variation needs its own custom fields. Say if you need to add a unique UPC or EAN code. This turned out to be surprisingly simple. Thanks to Remi Corson for the code.

PS. You should check out Remi’s page for pretty much ANYTHING Woocommerce related. It is basically an infinite well of Woo knowledge.

Taxonomy Description WYSIWYG

On sites where we are using custom post type taxonomies, we often want to have archive page. The problem, is the description field for a taxonomy is a simple textarea field. WE WANT MORE! Here is the code needed to replace the “Description” textarea field with a WYSIWYG field.

This was stolen verbatim from qwerty qwerty over on WordPress StackExchange.

Sort Posts by Date and Title

Another quick post with basic code needed to sort the posts page.

HTML / PHP Markup

Javascript / Controls


What you can expect to see (basically):

Sort Post Controls

Note: Requires bootstrap-datepicker.


Filter Post by Category

Just a quick post with the code needed to filter the posts page based on a category dropdown.


Upload a PDF from URL

We often have to do a lot of imports from old databases / sites. This means getting images and other files and adding them to the new site’s media library and attaching them to the new post that is related to the old site’s object / page / post. With images I always used media_sideload_image and that is easy enough.

media_sideload_image example:

So that works well enough for images. However, if you want to upload any other file types, like PDFs, you need to use a different approach.

There we go! Between those 2 functions above you can upload pretty much anything with a valid URL to your media library!

NOTE: I am also using another function called url_exists(). This is a simple function that just checks to make sure there is actually something being returned from the given URL.

FINAL NOTE: Obviously I didn’t wrap most of the above code in a function but I do usually convert the above code to a function for easier use. Feel free to set that up for yourself…or not 🙂