• Skip to main content

Julian Thomas Screawn

B.A. ,B.ED. ,M.ED.

  • Home
  • About
  • Websites
  • Resources
  • Coding
  • Contact

Add dynamic WordPress Gallery to header with lightbox popup using Custom Post Type

2025/05/15

Using plugin Lightbox Photoswipe:

https://wordpress.org/plugins/lightbox-photoswipe/

add_action( 'genesis_after_header', 'wpsites_after_header' );
function wpsites_after_header() {
	

if(is_front_page()){

   $type = 'home_images';
   $args = array(
        'post_type' => $type,
        'post_status' => 'publish',
        'posts_per_page' => -1, 
   );
    $query = new WP_Query( $args );
	
	$ids=array();

    if (have_posts()) :

        // Start the loop.
        while ( $query->have_posts() ) : $query->the_post();
  
                if ( has_post_thumbnail() ) {
					
				$featuredID = get_post_thumbnail_id();
                $ids[]=$featuredID;
                }
      
        // End the loop.
        endwhile;
  $list = implode(', ', $ids);

echo do_shortcode('[gallery link="file" size="large" columns="4" ids="'.$list.'"]'); 

 endif; 
 
	

}
}

Filed Under: Genesis Framework, Wordpress

Copyright © 2025 · Servicing Moncton, Dieppe, Riverview and beyond! · Moncton Meditation · Moncton English Tutor