Quantcast
Viewing all articles
Browse latest Browse all 1037

WordPress Tips: How to Check if Post / Page has a Gallery

Image may be NSFW.
Clik here to view.
WordPress-gallery Crunchify

The Gallery feature allows you to add one or more image galleries to your posts and pages. Up until WordPress 3.5, the gallery shortcode was commonly used in its most basic form:

[ gallary ]

Following 3.5, gallery shortcodes now include the image IDs by default. Like this:

[ gallary ids="5,153,543,464" ]

Below code will help you find 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 'Post/Page has no gallery';
}else{
  echo 'Post/Page has gallery';
}

The post WordPress Tips: How to Check if Post / Page has a Gallery appeared first on Crunchify.com.

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 1037

Trending Articles