Skip to content

Instantly share code, notes, and snippets.

@annalinneajohansson
Created December 6, 2013 18:18
Show Gist options
  • Save annalinneajohansson/7829632 to your computer and use it in GitHub Desktop.
Save annalinneajohansson/7829632 to your computer and use it in GitHub Desktop.
Allow array check for shortcode (based on has_shortcode)
<?php
function hip_has_shortcode( $content, $tags ) {
if( is_array( $tags ) ) {
foreach ( $tags as $tag ) {
preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
if ( empty( $matches ) )
return false;
foreach ( $matches as $shortcode ) {
if ( $tag === $shortcode[2] )
return true;
}
}
} else {
if ( shortcode_exists( $tags ) ) {
preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
if ( empty( $matches ) )
return false;
foreach ( $matches as $shortcode ) {
if ( $tags === $shortcode[2] )
return true;
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment