Posted by & filed under WordPress.

Adding this snippet to your WordPress theme will let you check to see if a post contains the gallery shortcode. Add this code to the single.php template of your WordPress theme inside the loop.

if (get_post_gallery() ){
  echo 'has gallery';
} else {
  echo 'has no gallery';

If you want to show the gallery after you check if one exists replace echo ‘has gallery’ with the following code.

echo get_post_gallery();

Leave a Reply

Your email address will not be published. Required fields are marked *