General answer: you can call wp_enqueue_script()
directly inline in the template, as of WordPress 3.4 (IIRC).
So, if you have:
<script src="https://wordpress.stackexchange.com/questions/82668/myscriptforthispageonly.js"></script>
You could replace it with:
<?php wp_enqueue_script( 'this-page-script', get_template_directory_uri() . '/myscriptforthispageonly.js', array( 'jquery' ), null, true ); ?>
Edit
From this comment:
This is from within a page. As in a WordPress page. No templates. Imagine you are writing a WordPress blog post update, you switch to HTML vie
Your best course of action would be to define a shortcode for the user to put into the post content, instead of putting a <script>
call itself directly in the post content. Then, in your shortcode callback, you can call wp_enqueue_script()
.
Related Posts:
- What are the benefits of using wp_enqueue_script?
- wp_register_script multiple identifiers?
- wp_enqueue_script adds only the first script
- Why is JavaScript being added to header as application/oembed?
- Javascript asset not enqueuing with the rest
- JavaScript Libraries in WordPress
- Setting Variable Path to Template Directory inside Script
- Dequeue set-post-thumbnail.min.js
- What does wp-embed.min.js do in WordPress 4.4?
- wp_add_inline_script without dependency
- How to use wordpress default Password Strength Meter script
- wp_enqueue_script() not working at all
- How to dequeue a script?
- How to use wp_localize_script in custom page template?
- How to use Head JS with all enqueued scripts?
- wp_enqueue_script : how to change loading order of scripts?
- Remove extra Google Maps script
- What does wp-list.js do?
- Is it possible to enqueue the Youtube API script or does it have to be inline?
- Include jQuery UI as a whole
- How to echo JS right after enqueued script to put it into noConflict mode?
- Correct place to register and enqueue scripts
- Combine enqueue js without affecting dependencies
- How to get a jQuery script to run on a page?
- Load multiple Javascript scripts
- WP script versioning breaks cross-site caching?
- require.js to load javascript
- Including javascript for a shortcode
- How to add extra attributes to the script tag added via wp_localize_script()
- Javascript not included
- Move all the JS files to the bottom|footer, the right way
- Disable unneeded scripts in a wordpress installation
- Javascript not working?
- How to add JavaScript file using wp_enqueue_scripts?
- How to properly add Bootstrap and JQuery Javascripts?
- wp_enqueue_script & constants?
- My scripts-bundle.js file is getting sent to the browser as a stylesheet css file. Help!
- wp_enqueue_scripts is not working in my plugin
- How to place script in footer?
- Exclude JS file from 404 error page
- Why won’t my scripts load?
- Building a slide down search box in wordpress
- Enqueue script if screen is greater than 500
- Enqueue Javascript After ALL Other Scripts (Including Async Scripts)
- Enqueue js script to footer
- Enqueueing a script and a style sheet not working
- Adding a Javascript slideshow to the home page
- Media library not working with wp_editor() on the front end
- Override do_item() Function to Add Extra Attribute to Scripts
- wp_enqueue_script not loading my custom js file
- Scripts not loading through function Method in WordPress Theme
- How to execute Javascript on a WordPress page?
- wp_enqueue_scripts not enqueing correctly
- Video script issue, JavaScript attribute remains ‘undefined’
- On click load iframe [closed]
- Add crossorigin to SCRIPT tag
- Add script to page at certain location in wordpress
- WordPress wp_enqueue_script only adds text to top of page source
- Getting a variable inside foreach from PHP to JS after localization
- How do I know if I should enqueue JS code or just include it in ONE PHP function?
- Failing to load my script files in wordpress! i can’t figure out what i’m doing wrong
- Removing admin javascript
- wp_enqueue_script() not working
- What to include to use jQuery UI Auto Complete
- Bootstrap bundle present in page source but not working
- wp_enqueue_script JS code runs too late (after user begins interacting)
- Get localize of a loaded javascript
- Dynamically add Js
- JS / jQuery in Elementor pages vs JS file
- Script widget works only in admin view but not in Public
- Load JavaScript on specific page with @wordpress compiler
- Add Paypal button redirect to a specific page after completing
- How to load Javascript code or functions.php later in a child theme?
- Enqueued script fails
- Error on clicking ‘Screen Options’ tab only at Products-related editor screen(s) and for specific user
- How to pass data to javascript in custom widget class
- Setting wp_enqueue_script correctly
- Why can I not deregister my style and script on custom post type?
- Proper way of minifiying java script files in wordpress theme
- Escaping quotes while enqueuing scripts
- How to register or enqueue script and stop it being called in head?
- How to correctly load this jquery script through the file functions.php?
- Adding javascript script to header via functions.php
- adding script tag in head of specific pages
- How to delay display of page elements until enqueued script has injected html
- load-scripts.php loads incorrect file names
- Enqueue concatinated JS file in WordPress
- wp_enqueue_scripts doesn’t work for template pages
- Javascript file doesn’t load
- early enqueueing javascript file in page template, not in functions.php
- jQuery + more won’t load in header
- WOW.js Script Tag Initialization Header/Footer
- Why can’t I load JS script in a plugin?
- convertEntities() used before it is defined
- JavaScript file successfully registered but does not render correctly
- wp_enqueue has a resource but doesn’t generate a script tag [duplicate]
- Orbit Slider and Events Manager Plug-in JavaScript
- How to load JavaScript modules with script_loader_tag hook?
- How to securely set dynamic HTML content with JavaScript?
- CCF7 Field numbuer prefilled after Click event