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
- Why does my JavaScript work in the browser console but does not work in my shortcode?
- 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?
- What hook runs wpautop on template content?
- 3 shortcodes 2 won’t render [closed]
- Styling parent based on a child element of a child in a WordPress page
- Slick slider not working on wordpress
- Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
- Using variable as shortcode parameter
- Limit total tags in the_content
- How to handle Ajax Calls, when using same shortcodes (with different parameters, e.g. ‘post-type’)?
- Display a block conditionally based on user input button
- Free Add to Cart Button on WooCommerce with Elementor – No Premium [closed]
- conditional shortcodes
- Facing Problem While Running WordPress Hook For Archive, Categories, Author, Date Pages Only
- wordpress shortcode url decode non Latin character
- I have custom html mixed with inline javascript that I want added to my WordPress site, how do I achieve this?
- Why does my shortcode query not working with search term
- Modal pop-up HTML code works on other sites or HTML viewers but not in the custom HTML block within a wordpress page?
- Custom shortcode with < in content
- Sending GravityForms to custom HTML
- Working with Shortcode, AJAX, Elementor
- How to use multiple values in “Shortcode”? [closed]
- How to exclude some cats from wp_list_categories using shortcut
- How can I create a shortcode that shows a list of categories on the single product page?
- Shortcode return vs echo. Return messes with data URLs, echo does not
- php codes ruins shortcode structure
- Is there a way to pull remotely generated XML, process it, and display it on a Managed WordPress page?
- Calling a function via a shortcode in javascript
- Array to String Conversion warning in shortcode
- Getting the wrong featured image on archive page
- Shortcode to show author role on the author archive page
- Processing javascript on wordpress
- How to use useSelect to retrieve the currently default fontFamily?
- How can I remove the wp_autop filter from a shortcode block in a block theme page template (twenty twenty-three)?
- Product description is mixed in shortcodes
- How to add button to WYSIWYG to insert shortcode with params (filled in system popup)?
- How to make this shortcode not refresh the whole page when i use it on frontend
- Sidebar inside page conten
- shortcode appears as text in the search result
- Want to call shortcode after every blog post title automatically
- add a meta value to the shortcode twice
- short code output too early
- add_action to only be called if uploading media from the front end
- How to create blocks from shortcodes?
- How to add content region to a post or a page
- Global variable not showing in shortcode
- How to trigger shortcode loaded by CSS
- Is It Possible to Block Redirect Checker Tools from Knowing Where URLs are Redirected?
- Identify and style the paragraph beginning w/o a class: based on a combination of common characters (CSS, JS)
- Giving each loop post unique numbers so that WordPress would treat separately
- WordPress Gallery only allowed 10 times per post
- How do I create a shortcode that returns a logged in users’ email?
- How to use Javascript to get data from a WordPress form
- useSelect() plus resolver result is serving cached data incorrectly
- wp:shortcode works in block theme template file but not PHP include file
- Which PlugIns have a [subpages] shortcode? [closed]