One option would be to create a shortcode exclusively for that script. Even thought it’s not an elegant solution, it works. In your functions file (functions.php) of your theme add:
function custom_script_shortcode(){
$code="<script>";
$code .= 'var foo = "bar";'
$code .= '</script>';
return $code;
}
add_shortcode("custom_script_shortcode", "custom_script");
And in your post editor then add the shortcode:
[custom_script]
Just be careful when you assign your JavaScript to the variable $code so you don’t close the string with ” or ‘
Related Posts:
- addEventListener vs onclick
- How do I check if an array includes a value in JavaScript?
- JavaScript document.getElementById().value logs empty value
- What is console.log?
- window.onload vs document.onload
- Fetch: POST JSON data
- JavaScript hide/show element
- Copy array by value
- Compare two dates with JavaScript
- How do I empty an array in JavaScript?
- What’s the difference between event.stopPropagation and event.preventDefault?
- ReferenceError: fetch is not defined
- In reactJS, how to copy text to clipboard?
- SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag
- Uncaught SyntaxError: Invalid or unexpected token
- JavaScript TypeError: Cannot read property ‘style’ of null
- What is “assert” in JavaScript?
- How does the data-toggle attribute work? (What’s its API?)
- How to import image (.svg, .png ) in a React Component
- How do I embed PHP code in JavaScript?
- Make javascript alert Yes/No Instead of Ok/Cancel
- How to create a dialog with “yes” and “no” options
- Adding images to a Bootstrap Carousel with AJAX
- XMLHttpRequest cannot load XXX No ‘Access-Control-Allow-Origin’ header
- Uncaught TypeError: Cannot read property ‘props’ of null
- How to use iMonkey in an iOS app
- How to handle the `onKeyPress` event in ReactJS?
- ES6: Create Strings using Template Literals – Freecodecamp
- Youtube api – stop video
- Uncaught TypeError: Cannot read property ‘msie’ of undefined – jQuery tools
- Angular JS Uncaught Error: [$injector:modulerr]
- Nested objects in javascript, best practices
- How do I convert an integer to binary in JavaScript?
- What does window.jQuery and window.$ mean?
- How to change date format in JavaScript
- OnChange event handler for radio button (INPUT type=”radio”) doesn’t work as one value
- InvalidValueError: not an instance of HTMLInputElement
- How to clear react-native cache?
- Convert CSV data into JSON format using Javascript
- Can not solve: Geocode was not successful for the following reason: OVER_QUERY_LIMIT
- How to set Angular 4 background image?
- React-Router : What is the purpose of IndexRoute?
- SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
- ReactJS – .JS vs .JSX
- How to convert date to timestamp?
- ReactJS: Maximum update depth exceeded error
- React, Uncaught ReferenceError: ReactDOM is not defined
- How to implement “select all” check box in HTML?
- JQuery get the title of a button
- How to open a URL using PHP?
- Trying to load jquery into tampermonkey script
- Atom JavaScript Autocomplete
- How to format a UTC date as a `YYYY-MM-DD hh:mm:ss` string using NodeJS?
- JavaScript button onclick not working
- Invariant Violation: _registerComponent(…): Target container is not a DOM element
- How to count string occurrence in string?
- Finding the max value of an attribute in an array of objects
- How to initialize an array’s length in JavaScript?
- How to set text color for my d3 chart title?
- Defining a HTML template to append using JQuery
- How do I bind to list of checkbox values with AngularJS?
- Wildcard string comparison in Javascript
- jQuery select option elements by value
- How to change cursor from pointer to finger using jQuery?
- How to get value in an object’s key using a variable referencing that key?
- Button that refreshes the page on click
- jQuery equivalent of body onLoad
- Replace spaces with dashes and make all letters lower-case
- How to make `setInterval` behave more in sync, or how to use `setTimeout` instead?
- Adding Google Translate to a web site
- What does l10n.js do in WordPress 3.1? And how do I remove it?
- How to add javascript just before the closing body tag in the footer of WordPress
- How do I include js without register/enqueue?
- wp_localize_script with boolean and init
- WordPress loads whole jQuery UI library
- What is the Javascript event for an item being added to the cart in Woocommerce?
- Can the index.asset.php file be used with the enqueue_block_editor_assets action?
- How to remove p / br elements from gutenbergs editor
- contact form 7 repeatable fields calculations [closed]
- Listening change event of taxonomy term checkboxes in Gutenberg editor
- Adding inline JavaScript encoding issue
- a child theme not de-registering a patent javascript file
- Accessing theme customizer farbtastic object instances
- Customizer JS API: Defining active_callback for a section
- Don’t allow JavaScript in the content area
- How to locate a Javascript? It is there in HTML but not in any file [closed]
- Malware gdjfgjfgj235f [closed]
- Using javascript on my site to create nested tabs
- CDATA removing new line in script tag in wordpress
- Linking wp_enqueue can’t find the javascript file (adds “?ver=x.x.x” to the src)
- Gutenberg – useEffect manipulate DOM after block re-renders DOM
- My code will not execute in wordpress, even though I’ve been told the code is fine
- Javascript working on jsfiddle but not wordpress site?
- Drodown list return issue
- Spans in gutenberg
- Get a default customizeAction text for a section using Customizer JS API
- Put dynamic Javascript in header after doing operations
- Adding javascript blocks to a single file and adding it to the header
- custom page url slug needs illegal ?id=1 for javascript
- Use one javascript variable into another javascript file