To use wp_enqueue_script()
correctly, you need to launch your function with the action wp_enqueue_scripts
.
In your __construct() or init function
add_action('wp_enqueue_scripts', array($this, 'admin_script'));
You can enqueue both, scripts and styles, in this function.
Related Posts:
- How can I get a list of all enqueued scripts and styles?
- Styles and scripts inside template part
- Enqueuing a script before anything else
- is there a way to get all queued scripts/styles into a template without `get_header()`?
- How do I get the $handle for all enqueued scripts?
- How to properly dequeue scripts and styles in child theme?
- Can I add styles to footer with $wp_styles->add_data?
- How to load JQuery easing script in wordpress?
- How do I load custom scripts and styles for a page?
- How to remove some external js files from source?
- Select2 in WordPress
- wp_enqueue_script with dependencies doesn’t work
- Help with enqueing scripts in footer after init action
- How to load script-related styles automatically?
- How to cancel `wp_print_scripts`?
- How do I enqueue a JavaScript in my footer via the functions.php file?
- Retrieve URL of Script/Style and Dependencies
- Do I need to register my own created .js and .css files
- Is there a way to list all the JavaScript scripts that are actually loaded by WordPress? Do we care?
- wp_dequeue_style and wp_dequeue_script not working on server but does work on local xampp
- get_template_directory_uri() gives me wrong path when I try to use wp_enqueue_style
- why quotes shown in WordPress?
- I want to set global directory locations for my CSS and JS locations. How?
- How do I pass $in_foooter to wp_enqueue_script() without passing other params?
- How to get, in WP page’s script, a wp enqueued script (in Functions.php)?
- How do I display the handle for all front-end enqueued scripts in plugin options page?
- Load CSS/Javascript in frontend conditionally if block is used
- Cannot deregister a script using wp_deregister_script
- Load plugin scripts and styles only on plugin page
- Removing specific style from wp_head
- How to dequeue / deregister any theme styles and scripts
- How can I dequeue a Plugin Stylesheet?
- Using wp_enqueue_script on shortcode function handler
- Enqueue script only for IE
- Conditionally dequeue dependency of scripts
- Including javascript for a shortcode
- Trigger a php file on every post or page if a condition is met
- wp_enqueue_script vs. wp_register_script
- How to dequeue / deregister parent theme style
- Enqueueing Scripts on a Custom Top-level Menu Page
- How to switch css files according to devices and button click?
- Performance-wise, is it better to enqueue a (small) script on every page or test to see if it’s needed?
- Stop WordPress editor embedding links
- Relative path instead of absolute for wp_enqueue_script
- Enque Typekit Fonts – Not Found
- Do we have to register JQuery if we want to use it in wp_enqueue_script()?
- wp_head() – list hooked actions with priorities?
- using conditionals on enqueue styles
- Including files in Child Themes
- Can’t load JS File
- Add stylesheets and js to template files when shortcode is used
- Exclude external uri for css and js version
- How to enqueu php files with custom variable & conditionals?
- Change script type and src of plugins in theme
- List All Enqueued Scripts and Styles
- How to enqueue the script without hardcoded in the theme files?
- Why is .map being added to the end of my file path?
- How can I properly enqueue tags in WordPress to use with Web Components?
- Custom script file enqueue has “?ver=4.5.1” when loading and doesn’t update
- get_stylesheet_directory() in child theme breaks parent scripts
- JavaScript is not enqueuing
- Why is JavaScript being added to header as application/oembed?
- browser showing connection was reset while accessing posts from local host
- My stylesheets are not enqueuing
- wp_enqueue_style referencing parent theme
- add WordPress script to page conditionally by category
- Javascript asset not enqueuing with the rest
- load jquery in footer not working
- Fatal error: Call to undefined function wp_enqueue_media()
- javascript file is not enqueing
- Enqueueing Scripts and Styles to page template that has html
- Calling wp_localize_script in a different function
- Stop a plugins js and css from loading on all pages and show up only where it is called
- Setting Variable Path to Template Directory inside Script
- thickbox never gets called (weird behavior)
- Filter enqueued styles and scripts
- Advanced method to control cache of enqueued style/script
- WordPress Sudden Loss of All CSS And Tons of JQuery Errors
- wp_enqueue_script was called incorrectly. Scripts and styles
- Dequeue styles with query doesn’t work
- Unqueue css file from specific page
- Modifying an enqueued script URL
- Changing the CSS with a plugin
- Enqueue registered dependencies only when necessary
- wp_enqueue_scripts action from a plugin overrides theme wp_enqueue_scripts no matter what the priority setting
- Trouble with wp_enqueue_script
- Can’t get jquery script to work
- Proper use of wp_localize_script?
- Prevent caching when using wp_enqueue_script?
- Should I be enqueueing styles/scripts once and then dequeueing them?
- List all non-admin enqueued files
- How to load default wordpress scripts
- css3-mediaqueries-js failing with child theme
- Ajax navigation and scripts loaded only on certain pages
- Enqueueing Script to footer puts it at the very bottom
- Bootstrap 4 Optimization
- Enqueue Script in custom plugin before other
- wp_script_is(‘enqueued’) true, but file not requested in HTML
- Should I use wp_register_style(), wp_enqueue_style, or both?
- Auto updating JavaScript dependancy in functions.php