In en earlier post I’ve showed you how we can add a like it button to a post/page without a plugin.
I’ve got a message asking how to also add this kind of button to a category/tag page. As we have stored the
likes data as a post meta for posts/pages, similarly if we can also store it for a category/tag, this should be an easy task.
Fortunately WordPress 4.4 “Clifford” introduced term meta data which allows you to save meta values for terms in a similar way to post meta data.
Four new functions were introduced to handle create, read, update and delete operations for term meta data:
add_term_meta(): adds the meta data
update_term_meta(): updates existing meta data
delete_term_meta(): deletes meta data
get_term_meta(): retrieves the meta data
Under the hood, these functions use the same code that the corresponding functions for post meta data use as well.
And we are going to use them for our like feature for category/tag and custom taxonomy archive pages.
Follow below steps to add the button.
Add these codes to your
In Line 39, the
Create a new
tax-like-it.js file and put below codes to it.
The look of the button depends on your theme’s styles, you can customize it on your needs.
Usage – Put this line of code to the category/tag or any other custom taxonomy archive page.