Last active
April 6, 2022 21:46
-
-
Save mae829/1842e17cd0d9a4622c14ff228eba4835 to your computer and use it in GitHub Desktop.
WordPress - function to detect if a page/post has a gallery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Has Gallery | |
* | |
* Detect whether the page/post has a gallery. | |
* | |
* @return boolean True if page/post content has a gallery, else false. | |
*/ | |
function has_gallery() { | |
global $post; | |
if ( ! empty( $post ) && is_singular() ) { | |
$content = $post->post_content; | |
if ( has_shortcode( $content, 'gallery' ) ) { | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment