There are quite a few default scripts installed along with WordPress including Scriptaculous, jQuery and ThickBox to name just a few. For a recent job, I needed to include a popup of member details, driven off of a dynamically created hyperlink. As I searched WordPress.org for a solution, I came across a Function Reference for the wp_enqueue_script. I was intrigued to learn that ThickBox was delivered with WordPress, so I started looking for ThickBox related plugins. There are many of them, but I couldn’t find any that worked through dynamic hyperlinks. They all seemed to use short codes in posts or pages.
Using ThickBox with dynamic hyperlinks is actually very simple. It’s so simple, it’s easier than installing a plugin. It requires modifying your theme’s functions.php file. To do this, open functions.php in the theme editor and add the following code at the bottom of the file:
wp_enqueue_style('thickbox.css', '/'.WPINC.'https://c4u5s8j9.rocketcdn.me/js/thickbox/thickbox.css', null, '1.0');
Save the file and you’re done. Next, when you construct your hyperlink, include a class=’thickbox’ in the declaration.
<a class="thickbox" title="Popup Title" href="http://www.your-url.org/displaycode.php?id=5&height=300&width=400">Link Text</a>
To understand how the displaycode.php program works, see Raising the WP eMember Public Directory Bar to the Next Level.