您可以创建自己的函数,
// check the current post for the existence of a short code
function has_shortcode( $shortcode = NULL ) {
$post_to_check = get_post( get_the_ID() );
// false because we have to search through the post content first
$found = false;
// if no short code was provided, return false
if ( ! $shortcode ) {
return $found;
}
// check the post content for the short code
if ( stripos( $post_to_check->post_content, \'[\' . $shortcode) !== FALSE ) {
// we have found the short code
$found = TRUE;
}
// return our final results
return $found;
}
在模板中编写一个条件,如,
if(has_shortcode(\'[gallery]\')) {
// perform actions here
}
来自此的想法
NetTuts link