<?php
// overwrite the page content to display gallery/collection preview

function gg_manage_preview($content) {
	if(
        (int)get_option('gg_preview_pag') == (int)get_the_ID() && 
        is_user_logged_in() && 
        (isset($_REQUEST['gg_gid']) || isset($_REQUEST['gg_cid']))
    ) {
			
		// gallery preview	
		if(isset($_REQUEST['gg_gid'])) {			
			$content = do_shortcode('[g-gallery gid="'. (int)$_REQUEST['gg_gid'] .'" filters="1" search="1"]');
		}
		
		// collection
		else {
			$content = do_shortcode('[g-collection cid="'. (int)$_REQUEST['gg_cid'] .'" filter="1" random="0"]');
		}
		
		
		return $content;
	}	
    
    return $content;
}

add_filter('the_content', 'gg_manage_preview', 9999);