Assuming the first block of code is executed when your plugin is launched, the has_shortcode
function is prescanning the post content to check if the shortcode is present. You then enqueue the scripts. That will work, because plugins are initiated before the scripts are enqueued (init
hook comes before wp_enqueue_scripts
hook).
If you enqueue scripts inside the shortcode, the function will be executed when the post content is assembled. At that point WP is already past the wp_enqueue_scripts
hook. The scripts will then end up in the footer, which may impact their behaviour.
If you use do_shortcode
directly in a template, your function with has_shortcode
will do nothing, because it only reacts to stuff that is inside the post content. You will have to replicate the circumstances under which do_shortcode
will be executed in the template during plugin initialisation to enqueue the scripts.
Related Posts:
- do_shortcode() doesn’t work if shortcode contained in variable, works if shortcode passed as string
- Plugin shortcode won’t work on a custom template file [closed]
- Where to find the code used to render a page that has a shortcode and a template defined?
- How to use template inside plugin shortcode with variables for big HTML code
- how to display a template.php in a shortcode
- How to add HTML to a template only when user is logged out/ not registered
- WP Customer Reviews call short code on another page [closed]
- Display HTML5 jQuery Audio Player On Front Page
- Create custom page templates with plugins?
- How to include code only on specific pages?
- Consuming an external API in WordPress?
- Custom Taxonomy in plugin and template
- PHP Deprecated: Non-static method should not be called statically
- Loading shortcode with ajax
- Cannot strip JW Player shortcode?
- How can I add a custom header to a custom template in a plugin without using the theme folders
- How to pass multiple values in shortcode?
- append stylesheet via shortcode
- Calling function from within functions.php returns unwanted value
- plugin shortcodes not working on custom theme- unsure how to fix
- How to list all active and specific shortcodes in wordpress
- Nested shortcodes
- Creating a wordpress plugin where users can override templates
- shortcodes displaying outside of content area with echo statement, not what I wanted [duplicate]
- Trying to count the total number of paragraphs inside a blog article
- How Can I Pass the Shortcode’s $atts Variable to the Plugin’s Javascript Function
- Adding json as params to shortcode
- Shortcode is not working in homepage page template (custom front page)
- May i Use ShortCode in Template?
- Can we use a webservice with WordPress?
- How can I create a custom shortcode that will return a custom post type by ID?
- List Category Posts rewrite necessitates rewrite of customised templates
- AddToAny shortcode in the loop
- WordPress comments not appearing in blog posts, likely because of Redux template. Could I fix this with a plugin that adds a comment form as a block? [closed]
- How to add an automatic refresh in WordPress for a Page/Post or an embedded OneDrive/Excel HTML Code?
- Making a Template for a CPT created by a plugin
- (FES EDD) New vendor submission page is blank
- How to display (plugin?) output on a single page (not a widget, probably not a short code) – template, plugin, combination?
- Nested shortcode functions accessing variable
- Advanced Custom Field DatePicker [closed]
- Calling an attribute from a plugin shortcode
- accessing wp.media api from a tinymce plugin
- Creating shortcodes in plugin
- Visual Composer shortcode for child theme dir
- How to create a custom shortcode based on the layout?
- Create shortcode to echo javascript
- Redirect to another page using contact form 7? [closed]
- changing posts layout in ultimate member profile plugin
- Custom Shortcode Broken in WordPress 3.1
- Namespaced shortcode?
- Why shortcode always displayed after footer not in body
- Why am I unable to load scripts in head in plugin?
- Displayed content disappears when adding attributes to shortcode
- How do I pass custom shortcode-extracted variables (taxonomy) into a query function for WordPress RoyalSlider?
- convert more tag to shortcode
- Shortcode does not expand in Facebook like
- Plugin Admin Menu Boiler Plate
- Override/ignore CSS from active theme as not to interfere with my custom CSS
- Opening a JQuery modal window on click of a button with a JQuery plugin
- strange shortcode error: does shortcodes requires any dependency?
- How to rewrite URL and get the values?
- Is there a good way to load tiny_mce_popup.js through editor.windowManager.open?
- How to prevent tabs from opening all at once
- Executing Javascript in Plugin
- Shortcode and variable
- reCAPTCHA on page template without plugin
- How can I achieve this, using shortcodes
- Pull comments from one page/post into another page/post?
- Creating New Dynamic Fields for a Certificate (Number Generation, Code Referencing, and more)
- How To Use do_shortcode with WooCommerce One Page Checkout
- How to get current cart values using WC_Shortcodes?
- Can I add Short Code Of A Plugin In The Code Editor of WordPress?
- insert og image link in wordpress post
- Get a value from a shortcode for another function
- How to call function in WordPress on button click?
- Hide content for specific users with id
- Why is my shortcode not working?
- using WPPB shortcodes without the plugin
- save short-code in my custom plugin settings problem missed something
- Do_shortcode before send email content
- WordPress show descriptions under images in gallery
- Customize plugin templates
- Modify Plugin PHP Class in Child Theme – Correct Method
- Meta box or shortcode help
- function of parent not working in childtheme
- Convert HTML5/CSS3 site to WordPress Theme (need a lot of plugins) or just use the API?
- Call/Run a Mathematica (.m) Shell Script from WordPress Page/Blog
- Posting code inside the post instead of in the template file using shortcode
- How to use shortcode of any plugin to show it visually where i want?
- Why function hooked using object are executing at all time?
- How to Set Limit with WordPress Get Bookmarks Shortcode
- Need to change contact email depending where user is from
- Pulling RSS from site and display it in posts
- Trying to Understand Shortcodes.
- Shortcode return is printing a 1 afterward
- Any way to hook into WP after a page displays?
- Integrate Razorpay quick payments plugin with contact form7 plugin
- Invalid argument supplied for foreach()
- How can I add a zip code service availability checker in WordPress without Woocommerce? [closed]
- Shortcode cannot parse attributes within double quotes. ” is becoming ” breaking my shortcode