Function Signature:
has_shortcode
Function Description:
Function Examples:
⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Check if a post content has a specific shortcode
$post_content = get_the_content();
if ( has_shortcode( $post_content, 'gallery' ) ) {
echo 'This post contains a gallery shortcode.';
} else {
echo 'No gallery shortcode found in this post.';
}
// Example 2: Check if a specific page template contains a shortcode
if ( is_page_template( 'custom-template.php' ) ) {
$page_content = get_the_content();
if ( has_shortcode( $page_content, 'contact_form' ) ) {
echo 'This custom template page contains a contact form shortcode.';
} else {
echo 'No contact form shortcode found in this custom template page.';
}
} else {
echo 'This is not the custom template page.';
}
// Example 3: Validate if a widget contains a specific shortcode
$widget_content = get_widget_content( 'custom_widget' );
if ( has_shortcode( $widget_content, 'video' ) ) {
echo 'The custom widget contains a video shortcode.';
} else {
echo 'No video shortcode found in this custom widget.';
}