This page redirects to an external site: https://developer.wordpress.org/reference/functions/has_shortcode/
Languages: English • Italiano • Reference/has shortcode 日本語 (Add your language)
Controlla se il contenuto passato contiene uno specifico shortcode.
<?php if ( has_shortcode( $content, 'gallery' ) ) { } ?>
Lo shortcode deve essere registrato con add_shortcode() per essere riconosciuto.
<?php
$content = 'Questo è del testo, (forse ottenuto con $post->post_content). Contiene lo shortcode [gallery].';
if( has_shortcode( $content, 'gallery' ) ) {
// Il contenuto ha uno shortcode [gallery], quindi questo controllo restituisce true.
}
?>
Accoda uno script quando un post usa un certo shortcode.
function custom_shortcode_scripts() {
global $post;
if( has_shortcode( $post->post_content, 'custom-shortcode') ) {
wp_enqueue_script( 'custom-script');
}
}
add_action( 'wp_enqueue_scripts', 'custom_shortcode_scripts');
has_shortcode() si trova in wp-includes/shortcodes.php.