Title: Use Lightbox in Custom Code
Last modified: March 19, 2018

---

# Use Lightbox in Custom Code

 *  [viktoriamf](https://wordpress.org/support/users/viktoriamf/)
 * (@viktoriamf)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/use-lightbox-in-custom-code/)
 * Hey there,
 * I’m currently working on a Plugin for my page. I’ using custom post types to 
   display a photography portfolio. I want these images to be opened in a Lightbox
   onclick. I copied the source code from my page where I’m using the Lightbox in
   King Composer and made my adjustments, but I can’t get the Lightbox to work.
 *     ```
       function displayPortfolio() {
   
               $args = array( 'post_type' => 'vmf_portfolio', 'posts_per_page' => 10 );
               $loop = new WP_Query( $args );
   
               echo "<div class='portfolio-container'>";
   
               while ( $loop->have_posts() ) : $loop->the_post();
   
               echo "<div class='kc_single_image'>";
               echo "<a rel='prettyPhoto[portfolio]' class='kc-image-link kc-pretty-photo kc-pt-loaded' data-lightbox='kc-lightbox' href='". get_the_post_thumbnail_url() . "' title='' target=''>";
               echo "<img src='" . get_the_post_thumbnail_url() ."' class='special-img' alt=''>";
               echo "<div class='kc-image-overlay'><i class='fa-search-plus'></i></div>";
               echo "</a></div>";
   
               echo "</div>";
   
               endwhile;
               }
       ```
   
 * Everything’s working fine, the picture shows up, the hover overlay is working,
   but when I click the image, a new tab opens and not the lightbox.
 * Thanks in advance.
    Viktoria

The topic ‘Use Lightbox in Custom Code’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/kingcomposer_747172.svg)
 * [Page Builder: KingComposer - Free Drag and Drop page builder by King-Theme](https://wordpress.org/plugins/kingcomposer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/kingcomposer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/kingcomposer/)
 * [Active Topics](https://wordpress.org/support/plugin/kingcomposer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/kingcomposer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/kingcomposer/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [viktoriamf](https://wordpress.org/support/users/viktoriamf/)
 * Last activity: [8 years, 1 month ago](https://wordpress.org/support/topic/use-lightbox-in-custom-code/)
 * Status: not resolved