Monday, October 1, 2012

Check if post / page has a gallery

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 (strpos($post->post_content,'[gallery') === false){
  echo 'no gallery';
}else{
  echo 'has gallery';
}

No comments:

Post a Comment