I was recently asked if it was easy to integrate Isotope jQuery plugin into a WordPress website. It’s not uncomplicated to add isotope.js to your website - it’s just not as easy as linking a script to your header.
2 Ways to add Isotope jQuery Plugin to WordPress
As always, there are (at least) 2 ways to achieve this
- Create a page template for the purpose - with all the code you want
- Add the code to your themes function.php file and then create a page template
How to integrate Isotope jQuery with WordPress
There’s probably hundreds of tuts on the topic of integrating Isotope with WordPress and this is ‘kind of’ mine. In mid 2012 I launched my first Isotope jQuery plugin for WordPress … well it wasn’t a plugin. It was a page template you had to copy into your theme folder.
Isotope jQuery for WordPress page template
The page template and the instructions for it are still on my website … A lot of developers frown on the page template approach as novice coders will hardcode the js and CSS into the page template. Worse, the page template is stuck with your theme … so if you delete your theme, your isotope page will stop working as soon as you delete that theme folder.
Isotope jQuery for WordPress plugin
Towards the end of 2012, I launched my first WordPress plugin for Isotope - which was promptly pulled from WordPress plugin repo because the Isotope jQuery is not open source. So, if you are doing this at home, then be honest and go pay David / Metafizzy for his hard work and get a licence.
- and so the best approach is the function.php fileIf you open your theme folder then edit the file functions.php - It’s probably a blank file or includes code from whomever wrote your theme
You could then start to move code from my dbc_isotope.php file into the functions.php.
Functions you need to have are -
- function to register and enqueue the isotope.js
- function to register and enqueue the twitter bootstrap CSS (if you want) -
- You’d then create your own script / function to hook the CSS attributes to the isotope.js
- You’d then have to add a conditional function to determine what page templates will get the isotope treatment - Look up WordPress conditionals like is_home or is_archive
- Now you could view your website to check that isotope.js is being called and view source to check that the js script is being printed in the footer not header .. Isotope.js like a lot of jQuery can’t be called in your header.php page template.
Finally then, you’d modify your existing theme templates or create a new page template to make it all work the way you want.
Tags:Read more from my blog for an introduction and quick tips on developing in Hugo or UCTD.