Title: deactivating gallery shortcode on wordpress conditional
Last modified: August 21, 2016

---

# deactivating gallery shortcode on wordpress conditional

 *  [DoodleDogCody](https://wordpress.org/support/users/doodledogcody/)
 * (@doodledogcody)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/deactivating-gallery-shortcode-on-wordpress-conditional/)
 * 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/](https://wordpress.org/plugins/photospace/)

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

 *  Plugin Author [THRIVE – Web Design Gold Coast](https://wordpress.org/support/users/deanoakley/)
 * (@deanoakley)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/deactivating-gallery-shortcode-on-wordpress-conditional/#post-4962601)
 * See here [http://thriveweb.com.au/the-lab/wordpress-gallery-plugin-photospace-2/](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](https://wordpress.org/support/users/doodledogcody/)
 * (@doodledogcody)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/deactivating-gallery-shortcode-on-wordpress-conditional/#post-4962631)
 * 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](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.

 * ![](https://s.w.org/plugins/geopattern-icon/photospace_6d3670.svg)
 * [Photospace Gallery](https://wordpress.org/plugins/photospace/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/photospace/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/photospace/)
 * [Active Topics](https://wordpress.org/support/plugin/photospace/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/photospace/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/photospace/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [DoodleDogCody](https://wordpress.org/support/users/doodledogcody/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/deactivating-gallery-shortcode-on-wordpress-conditional/#post-4962631)
 * Status: not resolved