You’re pretty close!
What you can do is to register all of the scripts via the wp_enqueue_scripts hook normally and then just enqueue them in the shortcode callback. This is telling WordPress about the scripts and then allowing you to only enqueue them as needed:
add_action( 'wp_enqueue_scripts' 'register_all_my_scripts' );
function register_all_my_scripts() {
wp_register_script( 'per-pas-belanja-online', plugins_url('js/per-pas-belanja-online.js', __FILE__), array('jquery'), '1.0.0' );
}
function this_is_my_shortcode(){
wp_enqueue_script('per-pas-belanja-online');
return '<div id="poppedout">Blah</div>';
}
add_shortcode('bubba', 'this_is_my_shortcode');
Hope it helps!
Related Posts:
- How to loop through JSON data in wordpress WP REST API
- WP API V2 returning Invalid User ID
- Passing JSON data from WP Query into AJAX causing NULL errors
- Export all post from database to JSON only when the database gets updated
- Create a new user using WP REST API and declare meta object
- How Do I Add User Custom Field to REST API Response?
- API JSON Data in WordPress
- fetch_feed: retrieve entries in the appearing order, not chronologically
- Gutenberg custom block using only register_block_type() and HTML
- How can I export post data in xml format?
- how to decode % in app [closed]
- Upload a json file in php [closed]
- Why does running get_the_excerpt() when generating JSON file take 28 seconds vs. 599 milliseconds without it?
- How to send user data in json format to another server when user register on wordpress site in PHP
- Create dynamic pages from external JSON data without storing in Database?
- Parsing php string in jquery [closed]
- Vagrantpress + composer
- woocommerce registration form with klaviyo(don’t work with current user)
- wp_remote_get adding backslashes
- Creating a Multi-Level Associative Object Using AJAX
- Fetch post block/field data as JSON with WordPress API
- database sent to a JSON file
- Input data from email form not going to JSON file
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- Fetching instagram api not working on wordpress
- JSON REST API WordPress only showing first 10 categories
- entire JS folder not loading in a WP theme
- Retrieve Json data and create multiple pages with it
- How to clone all WordPress Rest API end points
- PHP error with a shortcode: “no suitable wrapper” for file_get_contents
- Sending simple variable on single page to WP JSON
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Issue with json decode in WordPress – value is not returning consistently
- How does one make a URL return dynamic JSON with custom Content Type?
- How can i send id of the currently posted form data through json response in custom wordpress plugin?
- Need help to create WordPress page that decodes a text file and publishes it in JSON format
- wp_send_json erase last value
- Complex PHP for json_encode > how to handle/output right?
- Can’t get_users info by using json_encode
- AJAX Filter WHILE Loop not working WordPress
- I want to use wordpress database in android app using json encode?
- Result from wp_send_json adds line feed
- Setting pages for posts
- Search in particular category in wordpress
- WordPress format json in postmeta table
- How to post data to a word press site in case of a mobile app
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- I am unable to fetch json data from wp_db
- JSON Object Value Show Undefine
- Force array to be a string [closed]
- get_body_params() is always empty in POST request
- How to enqueue structured data as file – jsonld file seems not to work
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- REST API custom endpoints for metaboxes
- WordPress Register Block with metadata
- How to pass php array to external js file in WordPress
- Woocommerce – how can i add items to cart using onclick – multiple items at once with custom prices
- I have issue with decoding json ex. ‘{“a”:”b”}’
- is it possible to run some php code within a wordpress page?
- Remove option to allow trackbacks/pingbacks from post page options
- Display certain amount of posts on taxonomy archive page
- Automatically generate Post/Page from searched Database item?
- get_page_by_title with an apostrophe in variable
- Add a Second Menu to a theme that only support 1 menu
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Sum the total amount of a specific product purchased per user and display in table
- Include a PHP file inside an array
- Deprecated: Function create_function() is deprecated [closed]
- displaying content that includes shortcodes within an echo
- trouble with page_id & highlighting current page
- How to hook a logout funtion for specific usr role in wordpress?
- Advice on creating a WP Archive Template with Custom Taxonomy (get_term_meta)
- create front-end users post list by specific category
- Foreach implode issue
- Error display post thumbnails for previous and next post
- get different meta-data of a complicated query at the same time
- Get only relevant sub-category of category “Genre” that applies to current product only
- How to escape echo for input tag?
- 400 bad request admin-ajax file upload
- Warning: count(): syntax problem of the count () function
- Reload page with a different shortcode when a user selects from a dropdown
- Woocommerce Add custom “Add to cart button” in single page with tags
- Displaying child taxonomy before parent
- Different home page for logged off users
- Widget Update problems using a for loop
- Send data from plugin to external database
- WP Admin Bar – Get current theme name as custom menu title
- Show custom default avatar instead of gravatar
- the_post_thumbnail unless video id is added
- ajax form function error
- New to WordPress & Freelancing [closed]
- Add a “Next Post” & “Previous Post” styled button manually to a post
- How to store the_post_thumbnail() value in a variable
- a problem in class in class-wp-hook.php
- How do I a custom search form by taxonomies?
- WordPress REST API – Custom field not added to pages
- do_blocks not working with a custom block
- How to change product title color in shop page if product has specific product tag (Woocommerce)?
- Display featured posts first, then display all others within a specific category in WordPress
- Changing src URL on page id