Use the approach below to enqueue your scripts using a single action hook:
/**
* Proper way to enqueue scripts.
* The same approach can be used to enqueue styles.
*/
function my_interface_enqueues() {
wp_enqueue_script( 'require-js', plugin_dir_url( __FILE__ ) . 'js/libs/requirejs/require.js', array(), '1.0.0', true );
wp_enqueue_script( 'main-js', plugin_dir_url( __FILE__ ) . 'js/main.js', array(), '1.0.0', true );
// Here, a sample stylesheet enqueued.
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'my_interface_enqueues' );
That should definitely work.
Related Posts:
- Conditionally enqueue a widget’s script/stylesheet in HEAD (only when present on page!)
- Loading external page template and enqueue script from plugin causes 403 forbidden error
- When can you get current page ID and initialize hooks right after?
- enqueue script only if it is not already enqueue
- Which method is best to enqueue scripts
- Declaring script dependencies between scripts enqueued with different action hooks
- Pass $this to function nested in another public function of the same class
- Dequeue / Deregister script and replace it with a new plugin
- Custom data-id wp_enqueue_script
- wp_enqueue_scripts not working inside shortcode
- Avoiding Duplicate function names in Post Loop (WP_Footer script)
- React JSX in WordPress Plugin Development
- Making a plugin only available on the front-end for the logged in super admin
- Enqueue WordPress plugin scripts below all other JS
- jQuery for custom plugin not working with Divi theme
- How can I remove the WordPress-Version (?ver=5.x) from my plugin
- Create shortcode to echo javascript
- Why am I unable to load scripts in head in plugin?
- Custom CSS not being added by plugin
- why the wp_register_script doesn’t work for register_activation_hook
- Why won’t wp_enqueue_script work within any plugin file?
- wordpress plugin add page when activate
- wp_enqueue_script doesn’t load JS in plugin
- Pass PHP variable to javascript
- Namespaces in WordPress – How do I initiate the main class?
- What areas to Unit test while building a plugin?
- Function to activate WordPress theme inside a plugin
- What is the correct way to check if WP_Filesystem can write to a directory without aking for username / password?
- Errors while using ajax from external wordpress page
- Pass A Value From Outside To A Plugin Variable
- shortcode doesn’t work
- Create or Update thousands of woocommerce products via PHP
- send_headers don’t work on wordpress multisite
- Why was my plugin rejected from the WordPress.org repository?
- Adding content before the loop in category pages
- admin_notices hook show message all admin pages after plugin activate
- Update Option Error: Notice: Undefined index
- Why this global array is returning NULL from a callback function
- How to define WordPress plugin shortcode globally for multisite?
- how to Include json manifest file in wp plugin
- Why my Plugin keeps deactivating automatically?
- Self deactivate plugins after an action occurs
- How to get current post user id
- Input with spaces in Shortcode attributes overwritten by defaults
- Unable to override pluggable function wp_mail
- Avoid class name collision when using third party libraries in plugins?
- switched from query_posts to WP_query, not working now?
- How to find the origin of a file upload from within wp_handle_upload?
- Ajax contact form widget plugin data not insert in database
- Install Plugin via Code
- How to output CMB2 select options from repeated groups select elements?
- Homemade plugin while using Themify Ultra
- How to deal with WordPress and Pocket API to automate content curation on my hosted wordpress blog? [closed]
- WP All Import – Execute Imports
- How to set taxonomy in custom plugin?
- Plugin development: Buggy plugin preview
- do_action() hook into load-(page)
- Which file of wordpress manage plugins functionalities?
- How can i create page through plugin
- Check if variable is set in filter
- Custom license for WordPress plugin
- Does using `add_action( ‘init’…` cause performance issues?
- How to write “alt” tag in image for wordpress code?
- Different custom templates for product category [closed]
- How to create plugin/ page that reads from database
- Plugin not properly prepared for localization
- WordPress Active Plugins
- is it possible to hook every page style?
- Redirect logged in user to somepage on every page view?
- How to add filter for wordpress plugin?
- Adding a jQuery modal dialog to the admin area
- Edit all $wp_scripts at once to $in_footer = false
- How to make a Product page without ordering and database
- wp_options not returning value for logged out users?
- How to upload large media file in chunks, without any plugin?
- How to store a secret for a plugin inside public_html
- Cannot run script properly with my custom plugin
- Cookie value changes back to previous value after changing
- Hide all Admin Notices and move on a separate page
- How to use functions found inside pluggable.php with my plugin files
- Is it okay to make a plugin to the WordPress repo, but limit it’s actions to maximum N events?
- Highlight admin menu items that are parent of existing core items
- Getting all woocommerce products from REST API call in plugin
- AJAX update fails for public/non-admin users
- WordPress Product Detail and catalog
- WordPress plugin changes not updating
- Create Database Tables on Plugin Activation hook
- Change page according to fetched GET Parameters
- Shortcode registered from a plugin not recognized
- How to change a specific page to custom page?
- Plugin keeps saying needs to be updated and it’s in a constant loop [closed]
- How use Dynamic hyperlink on each wordpress post?
- _e in wordpress +
- WordPress Code Access to Restricted Content without Registration
- Activate plugin button do nothing [closed]
- add_meta_box showing blank screen in my page
- Plugin translations are not loaded from translate.wordpress.org
- Use inline callable for hooks and filters
- Error in using ‘admin_enqueue_scripts’ action through a class
- How do i fix this error?