So yes, as you say you can’t pass an array to has_shortcode
, which is confirmed in the docs, so you need to do the ‘OR’ operation manually, which would look something like this:
$shortCodesToTest = [ 'wpdocs-shortcode-1', 'wpdocs-shortcode-2', 'wpdocs-shortcode-3'];
$anyShortCode = false;
foreach ($shortCodesToTest as $sc) {
if (has_shortcode( $post->post_content, $sc) ) {
$anyShortCode = true;
}
}
Now use the $anyShortCode
variable as you like – it will be True
if any of the shortcodes were found. For example:
if ( is_a( $post, 'WP_Post' ) && $anyShortCode ) {
wp_enqueue_script( 'wpdocs-script');
}
Related Posts:
- Conditionally Loading JavaScript/CSS for Shortcodes
- How to add stylesheets only to pages with specific shortcode?
- How to force that styles are enqueued in the header?
- Conditionally Loading JavaScript/CSS for Shortcodes
- Add inline style to pages where shortcode was used
- Shortcode inside text widget do not call enqueue style
- Show shortcode without executing it
- How to create a shortcode with 1 parameter (atts)
- How does a shortcode work?
- Run visual composer code in php page
- Remove wptexturize from a shortcode?
- Using shortcode in Post title
- Audio or playlist shortcode condition according to the amount of files on attachment page
- WP_enqueue_script inside shortcode?
- template_redirect to accompany with a shortcode
- Tinymce shortcodes within shortcode contents
- passing multiple parents value into a shortcode
- How do I preview the result of a shortcode in the TinyMCE editor?
- Raw output (preventing wpautop)
- Conditionally loading Facebook PHP SDK in shortcode
- WordPress shortcode doesn’t working on HomePage
- is_admin() returns false in save_post hook with Gutenberg editor
- Why are Shortcodes Disabled in Widgets by Default?
- Add attribute to shortcode dynamically
- Execute shortcode twice in the same page
- How to parse this shortcode?
- possibility to control embedded video timeline with buttons and links external to the player
- Add custom setting that uses radio button to WP Gallery
- Shortcode with hyphen doesn’t work
- Shortcode parsed incorrectly because of heredoc
- WordPress Gallery shortcode: Display one category ID only
- How to get gallery id inserted to a post?
- WordPress Shortcode show database row
- Shortcode “post_per_page” not working
- Shortcode is running in page editor
- Shortcodes won’t work on live environment
- Create shortcode in Child Theme?
- Create a short code to display a specific loop
- How to add shortcode to HTML file (not showing on website)
- How to wp_redirect on ‘init’ hook on condition of current post id?
- Buddypress shortcode for tabs [closed]
- Image Shortcode from ACF ID
- How to create a shortcode with html and php code
- PHP Running On CMS Side of WordPress
- Basic do shortcodes question
- What is this format called (nested shortcodes)?
- Problem with height in video shortcode
- do_shortcode doesn’t work on some pages
- Custom youtube shortcode that uses $content
- Best tools for preparing and styling a table [closed]
- When are Shortcode Attributes Available in Template
- Use another action instead of the shortcode API to display the last time a user logged in
- how to add shortcode in wordpress container [duplicate]
- Get array of shortcodes within string
- stop WordPress removing shortcode from content [closed]
- Adding a custom field to do_shortcode [closed]
- Clearfix Shortcode
- How and when to include shortcode source files
- Use full size images in a specific gallery
- contact form 7 database short codes [closed]
- how to create a fav icon shortcode?
- How to deal with WordPress bug: can’t use wrapped and unwrapped shortcode on same post
- Execute Shortcodes when submitting post
- Video shortcode, option are not rendered
- Create shortcode for each form field in contact form 7
- Auto embeds don’t work for attachment descriptions
- Color on Shortcode insert that creates a button
- shortcode doesnt work on excerpt
- Adding Author URL to Nav Menu via Shortcode
- Displaying an interactive web map on my wordpress site
- Date Shortcode in Image alt and title tags
- access shortcode atts in template part
- May an attribute have no value?
- How to set up posts per page on WP
- How to insert a short code into Contact Form 7 in WordPress that will call a function once the submit button is pressed
- SQL query to bulk change short code in all posts
- Display shortcode in text field with wordpress settings api
- How to strip header tags & shortcodes from the_excerpt()
- shortcode display metainformation as linked image
- Unable to make shortcode, what is wrong?
- How to display a page dependent on a url parameter supplied by a form/button page?
- Push Shortcode parameter to template
- latest posts shortcode with image
- WordPress plugin shortcodes not outputting anything
- WordPress Gallery with ID’s Shortcode not Working
- Featured image with link to post shortcode, image displaying above the post
- Video shortcode inside tabs shorcode NOT working
- How to stop unwanted splits in excerpts when using shortcodes for sliders or players
- How to add meta slider lite or other slider to main page header in pinboard theme
- shortcode change variable base on user
- Inserting shortcode is blanking excerpt – any ideas?
- Escaping a shortcode so it displays as-is [duplicate]
- WordPress do_shortcode first iteration
- If do_shortcode is blank, return some message
- Add a short code to a plugin
- Previous/Next with the same category
- I’ve broken the short code for Contact Form 7!
- echo a shortcode in a shortcode code?
- Applying if (get_post_meta) to new shortcode
- Add widget/shortcode to sidebar OUTSIDE of the theme