solid-pixel
3/3/2017 - 7:08 PM

Replace WP Gallery with The Grid plugin gallery

Replace WP Gallery with The Grid plugin gallery

 /*------------------------------------*\
   REPLACE WP GALLERY WITH THE_GRID PLUGIN
 \*------------------------------------*/

 $GLOBALS['the_grid_gallery'] = 'Gallery'; // add your grid name here
 // remove the native gallery shortcode
 remove_shortcode('gallery');
 // redeclare the gallery shortcode
 add_shortcode('gallery', 'the_grid_gallery_shortcode');
 function the_grid_gallery_shortcode($ids) {

     global $tg_gallery_ids;
     // get the gallery IDs and store them globally
     $tg_gallery_ids = explode(',',$ids['ids']);
     // show an existing grid
     return The_Grid($GLOBALS['the_grid_gallery']);

 }
 function my_query_args($query_args, $grid_name) {

     // get the previously stored gallery IDs
     global $tg_gallery_ids;
     // if gallery IDs and previous grid used for the gallery shortcode
     if ($grid_name == $GLOBALS['the_grid_gallery'] && $tg_gallery_ids) {
         // all query parameters can be modified (https://codex.wordpress.org/Class_Reference/WP_Query)
         // rebuild the query arg to display a gallery of images
         $query_args['post_type']      = 'attachment';
         $query_args['posts_per_page'] = count($tg_gallery_ids);
         $query_args['post_status']    = 'inherit';
         $query_args['post__in']       = $tg_gallery_ids;
         $query_args['post__not_in']   = null;
         $query_args['tax_query']      = null;
         $query_args['meta_key']       = null;
         $query_args['meta_query']     = null;
     }
     // return the query args (modified or not)
     return $query_args;

 }
 add_filter('tg_wp_query_args', 'my_query_args', 10, 2);