Your JavaScript targets a HTML element with the id ‘banner_div’. So the first step is to output such an element in the shortcode.
add_shortcode( 'shortcode_name', function () {
$out="<div id="banner_div'></div>';
return $out;
} );
Now you need to save the JavaScript (everything between the <script>
tags) as a file. This you can now enqueue which is a whole other question. Here’s a question about doing this with a widget.
I would go with:
wp_enqueue_script( 'unique-name', '/path/to/script.js, array(), false, true);
What is going on here? Let me summarise for you.
- Param 1 is a name for your script.
- Param 2 is the URL for where-ever you put the script file.
- Params 3 and 4 are not used in this example
- Param 5 sets the script output to the footer so it runs after the widget div is on screen.
For more reference on the function wp_enqueue_script
see the codex page
Related Posts:
- How execute shortcode with javascript
- Enclosing Shortcode Within Another Enclosing Shortcode Breaks Output Functionality
- How to include code only on specific pages?
- Using get_option() in JavaScript
- Tinymce – How to hook before or after live shortcodes rendering?
- How to Output HTML tags in do_shortcode?
- Stray closing paragraph tag when using shortcodes
- Can I strip HTML tags in the “Compare Revisions” screen?
- Using action hooks inside of a shortcode
- WP_enqueue_script inside shortcode?
- Shortcode to Gutenberg-block: additional text on front-end and conditional display
- How to enqueue script based on post category?
- manipulate a plugins shortcode
- Remove and restore one shortcode
- How to handle shortcodes when using the JSON API
- ShortCode and extra
- Pass javascript array to shortcode
- Add custom setting that uses radio button to WP Gallery
- Two different inner shortcode under shortcodes or multiple nesting of inner shortcodes
- Get Required Assets (JS, CSS etc) for post using REST API
- How to add shortcode to HTML file (not showing on website)
- Scripts for shortcode: concatenate or load separately? [closed]
- Adding javascript actions to words in post content
- Add JS in footer via shortcode?
- Deactivate JS Script in Plugin Shortcode
- How can I collect and output all attributes of all executed ShortCodes?
- Regenerating WordPress shortcodes based on value with AJAX
- WordPress Shortcode / Only works in classic editor, gutenberg error / invalid json response
- Calling PHP Titles inside Javascript Markup
- Modifying the wordpress login page and then referencing it with a shortcode problem
- How to make shortcode which returns HTML?
- contact form 7 :create shortcode usable in email message [closed]
- Better way to display multiple plugin output on the same page?
- Returning HTML to Shortcode Block
- Shortcode not working inside div html
- Displaying an interactive web map on my wordpress site
- the_content() not showing the content in good order (with a shortcode)
- Multiple shortcodes with embedded JavaScript code in same page, how?
- Insert HTML in content property and render it using shortcodes
- Simulate shortcodes with javascript
- How to completely prevent WordPress from destroying/modifying my shortcode outputs?
- Which method to use when deleting posts from the front-end
- wp_register_script and wp_register_style when shortcode is used
- Is there a better way to output HTML as a shortcode?
- Hook into existing shortcodes to manipulate the attributes?
- (Google Map API) Geocode was not successful for the following reason: REQUEST_DENIED
- Onclick javascript to make browser go back to previous page?
- Error: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node’
- mailto using javascript
- Why is marquee deprecated and what is the best alternative?
- Refresh/reload the content in Div using jquery/ajax
- How do I load an HTML page in a div using JavaScript?
- Conditionally Loading JavaScript/CSS for Shortcodes
- Shortcodes, HTML tables, and multiple rows
- getEntityRecord without knowing the post type
- Does a shortcode with a single attribute have to use an array?
- Use [shortcode=”value”] instead of [shortcode att=”value”]?
- I dont want to show shortcode in tag
- Post loop created via shortcode not displaying shortcode in content
- Pass shortcode variables to template
- Is it possible to add a repeater field to TinyMCE’s option window?
- Shortcodes: Pros and Cons
- esc_attr not working in shortcode
- Can’t understand $atts in functions?
- Are .MP3 files with capital letter extensions allowed in [audio] shortcode?
- Get Posts shortcode plugin and meta_query?
- Gravity forms customize field markup for the same form appearing in different places
- accessing wp.media api from a tinymce plugin
- How to change to local video player on shortcode ultimate to video.js?
- Shortcode not showing anything
- return unformatted content in encosing shortcode
- Are Shortcode Attributes Always Passed As Strings?
- Show form per shortcode
- Default WordPress shortcodes not working?
- Pass fileurl parameter into shortcode from Advanced Custom Fields
- Sanitize or treatment of string in editor via shortcode
- Executing Javascript in Plugin
- Can’t render shortcode when html tag contains hyphen
- Display WordPress search results based on the selected Sub-Category
- Not to escape a text
- Add HTML to custom post type edit page
- How can I use javascript in specific posts without relying on a plugin?
- Pagination for custom posts loop
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- Modify [caption] shortcode so and are not used?
- How to Call Related Post based on Categories Inside Post Content with Shortcode?
- Cannot modify class property from shortcode handler function
- Site images are fixed in front of my site content [closed]
- Reusable Dynamic Taxonomy Shortcode
- Can’t place endwhile in the loop properly in a shortcode
- How to reduce the image size inside an icon? [closed]
- How to insert visual compser post grid shortcode in a custom page template? [closed]
- Shortcode tags appear on mobile themes
- Manipulated shortcode output
- Where is escaped the shortcode?
- Changing layout of defaul gallery output to masonry
- How to enable on custom shortcodes
- Nested ShortCode works inside the_content, but not outside of it
- Facing Problem While Running WordPress Hook For Archive, Categories, Author, Date Pages Only
- Working with Shortcode, AJAX, Elementor