I have created a page template that displays the featured image for all posts of a certain custom post type.

It uses a normal loop that is querying that specific custom post type. The thumbnails are being displayed using <?php the_post_thumbnail('project-thumb'); ?>

I now want to use a lightbox to display the rest of the images in the post. I believe that I need to use <?php wp_get_attachment_image_src(); ?>

For some reason I can't quite get my head around it. Can anyone point me in the right direction? Thanks in advance!

  • Thanks for joining WPSE. Glad to have you here! If @tosho's answer has solved the issue, please mark it as the correct answer and give him an upvote. This is good protocol and reward for those who spend time to craft answers. :) Sep 15, 2012 at 4:08

1 Answer 1


You could use WordPress’ built-in Thickbox script. Just place the following code somewhere before wp_footer();:

add_action( 'wp_footer', 't5_thickbox_jquery' );

function t5_thickbox_jquery()
jQuery( 'a img.size-medium, a img.attachment-thumbnail' )
    .addClass( 'thickbox' )
    .attr( 'rel', 'page' );

See this answer for more details.

  • Thanks, toscho! I didn't realize thickbox was build in. I am having another issue and I may be trying to do something that you cannot do. When the link with thumbnail is clicked I want lightbox to show all image attachments in a post, but the function I have is nesting anchor elements within an anchor element which I know is invalid HTML. Here is the function function portfolio_thumbnail_url($pid){ $image_id = get_post_thumbnail_id($pid); $image_url = wp_get_attachment_image_src($image_id,'screen-shot'); return $image_url[0]; }
    – jrelgin
    Aug 20, 2012 at 14:11
  • Sorry @toscho. New to stackexchange. Didn't mean to post above comment as is:-) But, not sure how to write a function that will display all post images in lightbox. Anyway, I will be using thickbox, so thanks again.
    – jrelgin
    Aug 20, 2012 at 14:24
  • @jrelgin If my answer solved your problem tick the little checkmark on the left side so other readers know it is solved. Our list of unanswered questions is already long enough. :)
    – fuxia
    Oct 6, 2012 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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