You were using action to enqueue script, instead you need to use filter hook. As, you are adding a new script to the scripts call.
However, if you used action hook for the wp_head
call it works there.
<?php
add_filter('wp_enqueue_scripts', 'colorboxJS');
function colorboxJS() {
wp_enqueue_script(
'colorbox',
get_stylesheet_directory_uri() . '/colorboxJSfile.js',
array('jquery')
);
}
?>
Related Posts:
- Register and enqueue conditional (browser-specific) javascript files?
- Correct place to register and enqueue scripts
- wp_register_script multiple identifiers?
- When to use add_action when registering/enqueuing scripts
- Is there a way to check for an attribute of a script when using script_loader_tag?
- Scripts not loading through function Method in WordPress Theme
- Add crossorigin to SCRIPT tag
- Failing to load my script files in wordpress! i can’t figure out what i’m doing wrong
- What does wp-embed.min.js do in WordPress 4.4?
- How to enqueue scripts on custom post add/edit pages?
- How to use wordpress default Password Strength Meter script
- wp_enqueue_scripts, wp_register_scripts, wp_print_scripts: i’m confused
- wp_enqueue_script() not working at all
- How to dequeue a script?
- Any advantage of using wp_scripts and is_IE when enqueuing scripts
- wp_enqueue_script : how to change loading order of scripts?
- 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?
- Combine enqueue js without affecting dependencies
- wp_localize_script with boolean and init
- How to disable hoverIntent in WordPress 3.3 admin
- require.js to load javascript
- wp_enqueue_script isn’t connecting my custom js file
- TinyMCE in a div / textarea on frontend?
- How to add extra attributes to the script tag added via wp_localize_script()
- How do I enqueue(or delay loading of) tags in individual page posts?
- Use js script from one plugin in another plugin
- Include Javascript as Plain (No file inclusion)
- Move all the JS files to the bottom|footer, the right way
- Can’t get JS code to work with shortcode
- Javascript not working?
- wp_enqueue_script adds only the first script
- Is it mandatory to enqueue any kind of Javsacript?
- wp_enqueue_script & constants?
- Can the index.asset.php file be used with the enqueue_block_editor_assets action?
- Deregistering a script in WordPress seems impossible
- wp_enqueue_scripts is not working in my plugin
- How to place script in footer?
- React JSX in WordPress Plugin Development
- Exclude JS file from 404 error page
- Building a slide down search box in wordpress
- Enqueue script if screen is greater than 500
- Script Localization doesn’t work
- Enqueueing a script and a style sheet not working
- Adding a Javascript slideshow to the home page
- Enqueue scripts all over but not in single.php
- Override do_item() Function to Add Extra Attribute to Scripts
- Proper way to enqueue a generated script that isn’t in a .js file?
- Enqueue scripts based on browser width?
- wp_enqueue_script not loading my custom js file
- Correctly enqueue scripts of type=text/paperscript (PaperJs Library)
- How to execute Javascript on a WordPress page?
- Why is JavaScript being added to header as application/oembed?
- wp_enqueue_scripts not enqueing correctly
- Video script issue, JavaScript attribute remains ‘undefined’
- How to register and enqueue JavaScript files without breaking plugin dependencies?
- Plugin Scripts no loading on options page
- Javascript on Registration Page
- admin_enqueue_scripts not rending JS file correctly
- Do I just put the html in a page when enqueueng or do I also have to reference js file from the html page [closed]
- Javascript asset not enqueuing with the rest
- 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?
- Including Styles and JS files to work ON my plugin interface
- Linking wp_enqueue can’t find the javascript file (adds “?ver=x.x.x” to the src)
- 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
- JS / jQuery in Elementor pages vs JS file
- Load JavaScript on specific page with @wordpress compiler
- Easiest way to find JS conflicts
- Script Loaded in WordPress but won’t run
- 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
- How to register or enqueue script and stop it being called in head?
- True parameter but jquery register in header and not in the footer with wp_register_script
- Adding javascript script to header via functions.php
- 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
- JavaScript and Google PageSpeed + wp_enqueue_script
- Javascript file doesn’t load
- Put dynamic Javascript in header after doing operations
- early enqueueing javascript file in page template, not in functions.php
- Dequeue set-post-thumbnail.min.js
- jQuery + more won’t load in header
- JS enqueue path (localhost)
- Why can’t I load JS script in a plugin?
- Script loaders vs wp_enqueue_script
- convertEntities() used before it is defined
- wp_enqueue has a resource but doesn’t generate a script tag [duplicate]
- How to load JavaScript modules with script_loader_tag hook?
- Uncaught ReferenceError: tippy is not defined
- Use add_action to run a script, but only on the post editor page
- How to securely set dynamic HTML content with JavaScript?