• I have the need to have a few pages use photospace and I use the default wordpress gallery system and shortcode to do so. However, I also have a custom post type where I would like to use the default wordpress gallery system on the front end. Is there a way to only add the shortcode in specific areas.

    In the code there is

    add_shortcode('gallery', 'photospace_function');

    I tried wrapping this in a wordpress conditional but that doesn’t seem to work, I assume add_shortcode is fired before wordpress queries the database for the post and therefore doesn’t know what kind of post it is.

    Can you think of anyway to accomplish this?

    https://wordpress.org/plugins/photospace/

Viewing 2 replies - 1 through 2 (of 2 total)
  • See here http://thriveweb.com.au/the-lab/wordpress-gallery-plugin-photospace-2/

    Template tag

    If you want to hard code this gallery into a page template you can do so with this code.

    <?php echo do_shortcode(‘[gallery]‘); ?>

    Thread Starter DoodleDogCody

    (@doodledogcody)

    That wasn’t quite what I was trying to achieve but I figured out how to get what I wanted. Here is what I did as an example in case someone else needs to do this.

    To correctly modify the gallery shortcode wordpress suggest to hook into the post gallery filter, instead of simply ovveriding with add_shortcode(‘gallery’). You can see that here http://codex.wordpress.org/Plugin_API/Filter_Reference/post_gallery

    I modified the code by commenting out the add_shortcode(‘gallery’) function and adding in the example from the link above and return an empty string on my specific conditional. This can be used by anyone in the future if they would like to use photospace in certain areas of the site but the default gallery on others.

    /* add_shortcode( 'gallery', 'photospace_responsive_shortcode' ); */
    
    function ddc_gallery_shortcode( $output = '', $atts, $content = false, $tag = false ) {
    	$return = $output; // fallback
    
    	global $post;
    
    	if( 'client-viewing' == $post->post_type ) {
    		return $return;
    	};
    
    	// retrieve content of your own gallery function
    	$my_result = photospace_responsive_shortcode( $atts );
    
    	// boolean false = empty, see http://php.net/empty
    	if( !empty( $my_result ) ) {
    		$return = $my_result;
    	}
    
    	return $return;
    }
    
    add_filter( 'post_gallery', 'ddc_gallery_shortcode', 10, 4 );

    the only other thing modified is setting the $my_result variable equal to the photospace gallery function.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘deactivating gallery shortcode on wordpress conditional’ is closed to new replies.