WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a Gallery View shortcode plugin. I wanna add an feature to that which is - Whenever someone clicks on any image in that gallery, that image should get open in a stylish popup window. Since I am seeking to add this feature to my own plugin, I can't even think to use another plugin. I tried to understand the coding of some such plugins but couldn't figure out any proper way to do so. Please suggest! Thanks!

share|improve this question
up vote 0 down vote accepted

1) enque thickbox on front end

add_action('init', 'myplugin_thickbox');
function myplugin_thickbox() {
    if (! is_admin()) {
        wp_enqueue_script('thickbox', null,  array('jquery'));
        wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0');

2) Add thickbox to all your images that are displayed by the_content();

function fb_add_thickbox($content){

    $content = preg_replace('/<a(.*?)href="(.*?).(jpg|jpeg|png|gif|bmp|ico)"(.*?)><img/U', '<a$1href="$2.$3" $4 class="thickbox"><img', $content);

    return $content;
add_filter('the_content', 'fb_add_thickbox', 2);

sources: http://wordpress.org/support/topic/how-to-implement-thickbox-to-all-images-which-contain-a-refered-link http://www.ultimatewebtips.com/how-to-use-wordpress-native-thickbox-support-in-front-end/

share|improve this answer
Why would i like to add another plugin with mine one? Doesn't it look stupid? – Sahil Jul 16 '13 at 6:53
Rather I would appreciate if you can provide me the straight-forward code. – Sahil Jul 16 '13 at 6:53
This code should do exactly what your looking to do. Are you refering to thickbox as "another plugin"? Because thickbox comes stock with wordpress... – Ronburgundy Jul 16 '13 at 12:38
I also fail to see where the above is not "straight forward code", look at the examples I gave you, they should give you an idea of what direction to look. – Ronburgundy Jul 16 '13 at 12:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.