When you enqueue a script with wp_enqueue_script()
it adds the <script>
tag part for you. If you have HTML that the script interacts with you will need to add that HTML to the page another way. You should not include the script tag in any HTML.
There are many options for adding HTML to a page, depending on where you need it:
- Adding it in the Text tab of the classic editor.
- Adding it with the Custom HTML block in the block editor.
- Creating your own block.
- Creating a shortcode.
- Creating a widget.
- Adding it to a custom page template.
Although I’d say that anything other than using a block is becoming obsolete at this point.
Related Posts:
- Building a slide down search box in wordpress
- Why is JavaScript being added to header as application/oembed?
- How to delay display of page elements until enqueued script has injected html
- Failed to load resource: the server responded with a status of 404 (Not Found)
- How to fix “Cannot read property ‘addEventListener’ of null” error [duplicate]
- How do I check whether a checkbox is checked in jQuery?
- How to make a word underline in Markdown
- How to play audio?
- How to play audio?
- Include another HTML file in a HTML file
- How to add jQuery code into HTML Page
- Bootstrap Dropdown menu is not working
- jquery SlideToggle effect in upward direction?
- Set timeout for ajax (jQuery)
- CSS height 100% percent not working
- Express Render not working return error: No default engine was specified and no extension was provided
- Jquery swipe left or right on mobile
- How to move an element into another element?
- Uncaught TypeError: Cannot read property ‘top’ of undefined
- How to move all HTML element children to another parent using JavaScript?
- How to print HTML content on click of a button, but not the page?
- Bootstrap 4 Dropdown Menu not working?
- document.getElementsByClassName().innerHTML always returns “undefined”
- Vue is not defined
- Error: ENOENT: no such file or directory, stat ‘/public/main.html’ at Error (native)
- onClick to get the ID of the clicked button
- HTML text input allow only numeric input
- How to change the buttons text using javascript
- How do I use this JavaScript variable in HTML?
- How to close current tab in a browser window?
- How to pass parameters using ui-sref in ui-router to controller
- How to write inside a DIV box with javascript
- What does ngf-select do and why is it needed for form validation?
- How to get height of div in px dimension
- Creating a div element in jQuery
- How to use in jQuery :not and hasClass() to get a specific element without a class
- Crop the image using JavaScript
- Adjust width and height of iframe to fit with content in it
- Force div to be topmost element of any and all webpages
- How to display raw JSON data on a HTML page
- Get class list for element with jQuery
- How to make an HTML back link?
- How to fix getImageData() error The canvas has been tainted by cross-origin data?
- HTML/Javascript change div content
- How To Save Canvas As An Image With canvas.toDataURL()?
- Why is jquery show() not working in example
- How can I use jQuery to run MySQL queries?
- Create a simple 10 second countdown
- Print a div content using Jquery
- Get the size of the screen, current web page and browser window
- How to enable a disabled checkbox dynamically?
- What’s the effect of adding ‘return false’ to a click event listener?
- Fully responsive HTML5 video
- When is a CDATA section necessary within a script tag?
- HTML anchor link – href and onclick both?
- How to create checkbox inside dropdown?
- How can I know which radio button is selected via jQuery?
- Positioning element at center of screen
- “Uncaught TypeError: Illegal invocation” in Chrome
- How to use aria-expanded=”true” to change a css property
- What does wp-embed.min.js do in WordPress 4.4?
- Remove extra Google Maps script
- What does wp-list.js do?
- Include jQuery UI as a whole
- How to echo JS right after enqueued script to put it into noConflict mode?
- How to wrap the content of the main tinyMCE editor with extra tags
- Move all the JS files to the bottom|footer, the right way
- Javascript not working?
- wp_enqueue_script & constants?
- wp_enqueue_scripts is not working in my plugin
- How do developers add “Smooth Transitions” to their sites?
- Exclude JS file from 404 error page
- Can I change an external script’s HTML?
- wp_enqueue_script not loading my custom js file
- Scripts not loading through function Method in WordPress Theme
- wp_enqueue_scripts not enqueing correctly
- Video script issue, JavaScript attribute remains ‘undefined’
- Javascript asset not enqueuing with the rest
- How do I know if I should enqueue JS code or just include it in ONE PHP function?
- creating a static HTML/JS/PHP page
- Setting Variable Path to Template Directory inside Script
- wp_enqueue_script does not recognize my js file?
- What to include to use jQuery UI Auto Complete
- Bootstrap bundle present in page source but not working
- Dynamically add Js
- Web cover page open when button clicked
- How to pass data to javascript in custom widget class
- Loading two versions of same JS libary
- Proper way of minifiying java script files in wordpress theme
- Adding javascript script to header via functions.php
- load-scripts.php loads incorrect file names
- early enqueueing javascript file in page template, not in functions.php
- jQuery + more won’t load in header
- JS enqueue path (localhost)
- Script loaders vs wp_enqueue_script
- wp_enqueue has a resource but doesn’t generate a script tag [duplicate]
- How to load JavaScript modules with script_loader_tag hook?
- How to securely set dynamic HTML content with JavaScript?
- Sending GravityForms to custom HTML