Is there any way to stop this
Don’t have JavaScript in your editor. It’s dirty and difficult to maintain (as you’ve found out).
Instead, you could:
- Use a page template
- Use custom fields (post meta)
- Use conditional code in your
functions.php
For 3), as an example:
function wpse_202946_script() {
if ( is_page( 'id_or_title_or_slug' ) ) {
wp_enqueue_script(
'my-theme-script-name',
get_template_directory_uri() . '/path/to/script.js',
null, // Dependencies
null, // Version
true // In footer
);
}
}
add_action( 'wp_enqueue_scripts', 'wpse_202946_script' );
Related Posts:
- Add Item to Custom TinyMCE Menu
- Strange gibberish JavaScript in Editor – site hacked?
- Close TinyMCE plugin window on click away
- Trouble adding JavaScript in visual editor (Sharpspring embed code)
- Custom wp.editor.initialize settings ignored
- JavaScript && operator in visual editor
- Popup box when Clicking on Insert into post button in wordpress
- wordpress 4.4 upgrade visual editor bullets select for not selected elements
- disable tags on wordpress text editor
- How to use WP switchEditors.switchto(this) JS function in your own script?
- VisualComposer/WPBakery Page Editor: Is any JS event triggered after the Edition pop-in is shown?
- Dynamically write in editor with Javascript
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- How to do associative array/hashing in JavaScript
- convert Hsl to rgb and hex
- How to play audio?
- How to write a countdown timer in JavaScript?
- TypeScript foreach return [duplicate]
- “Uncaught TypeError: Cannot read property ‘style’ of null at.. “
- Difference between document.referrer and window.parent.location.href
- JavaScript replace/regex
- how to render a react component using ReactDOM Render
- What does “javascript:void(0)” mean?
- What does this symbol mean in JavaScript?
- Go back button in a page
- ‘react-scripts’ is not recognized as an internal or external command
- how to get the last character of a string?
- Set timeout for ajax (jQuery)
- Escaping Discord subset of markdown
- ESLint Parsing error: Unexpected token
- Angular ForEach in Angular4/Typescript?
- Timers in React Native (this.setTimeout)
- CSS height 100% percent not working
- Angular 4 setting selected option in Dropdown
- bootstrap-datetimepicker for bootstrap 4
- Proper way to wait for one function to finish before continuing?
- XMLHttpRequest module not defined/found
- document.getElementsByClassName().innerHTML always returns “undefined”
- Bower: ENOGIT Git is not installed or not in the PATH
- Converting an object to a string
- How can I convert an image into Base64 string using JavaScript?
- Javascript checkbox onChange
- Attaching ‘onclick’ event to D3 chart background
- declaration or statement expected javascript/typescript
- The preferred way of creating a new element with jQuery
- How to pass parameters using ui-sref in ui-router to controller
- What does ngf-select do and why is it needed for form validation?
- What is jQuery Unobtrusive Validation?
- Add and remove multiple classes in jQuery
- How To Save Canvas As An Image With canvas.toDataURL()?
- NPM install fails with node-gyp
- How do I download a file with Angular2 or greater
- What are alternatives to document.write?
- What are differences between SystemJS and Webpack?
- How to find if div with specific id exists in jQuery?
- TypeError: $ is not a function WordPress
- Fully responsive HTML5 video
- Make Discord bot send picture with message with NodeJS
- RegEx for Javascript to allow only alphanumeric
- How to check for an undefined or null variable in JavaScript?
- HTML anchor link – href and onclick both?
- Can WordPress be made to support websockets?
- How to use wp.hooks.addAction() in React JS/Gutenberg?
- Remove extra Google Maps script
- single page wordpress
- initial open/toggle PluginDocumentSettingPanel panel in document setting block editor gutenberg
- How to add JavaScript code on WordPress properly?
- Disable unneeded scripts in a wordpress installation
- Restrict file types in the uploader of a wp.media frame
- Gutenberg getMedia() in post query doesn’t return all featured images
- Can I change an external script’s HTML?
- How to transform a legacy widget into a block
- const { __ } not working in IE11
- Adding and removing hidden buttons from WordPress Customizer Tinymce widget editor using javascript API
- Performance vs plugin genrated javascript
- Cannot use characters ” in jQuery script in WordPress
- How to install cool javascript feature in WordPress?
- How can I load certain JavaScripts only on blog pages?
- jQuery UI Tools (Flowplayer) Issues
- How can I leverage browser cache for minified JS or minified CS files?
- Normal for scripts to be loaded after body tag?
- print script on wordpress header after user registered
- How do I use this javascript correct with wordpress?
- How can I integrate yepnope.js with WordPress (and plugins)?
- How to set javascript options for select2 in PHP array of plugin
- Multiple jQuery inputs or binds in Customizer Control Javascripts
- How to display different content on the same page using different URLS
- Replace script attr or link
- Remove escape characters from JSON string pulled from a database
- Immediate (e.g. without DOMContentLoaded) JS not working
- Client side pre-save Javascript hook on all admin pages
- WP Gutenberg – custom block with two content fields
- Script not working in post content
- How to identify which javascript is being executed
- How to keep close a sub-menu under homepage? [closed]
- How to implement custom URL handler to access JS modal content? [closed]
- Contact form 7 hide and show fields depending up on the condition [closed]
- Javascript 2 elements dependent onclick .toggle [closed]
- wp_enqueue has a resource but doesn’t generate a script tag [duplicate]
- Use add_action to run a script, but only on the post editor page