script_loader_tag
filter was introduced in WordPress 4.1:
<?php
add_filter( 'script_loader_tag', 'my_script_attributes', 10, 3 );
function my_script_attributes( $tag, $handle, $src )
{
// change to the registered script handle, e. g. 'jquery'
if ( 'MY_SCRIPT_HANDLE' === $handle ) {
// add attributes of your choice
$tag = '<script id="customID" data-name="customDataName" src="' . esc_url( $src ) . '"></script>';
}
return $tag;
}
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
- wp_enqueue_scripts not working inside shortcode
- wp_enqueue_script fails to include in footer
- 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
- Does the number of downloads displayed for a plug-in in the WordPress.org plug-in directory include automatic updates?
- Namespaces in WordPress – How do I initiate the main class?
- 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?
- Is there a WordPress Plugin that allows voting “does this coupon work” on specific links like Retailmenot
- Pass A Value From Outside To A Plugin Variable
- shortcode doesn’t work
- Built in admin ajax hooks?
- dequeue not work
- Force plugin to fail activation
- Plugin: How should I handle deleting comments?
- wordpress plugin that show my reputation (points) in any stackexchange project in my wordpress blogs
- Why load_textdomain work but not load_plugin_textdomain?
- Passing select control value to block
- 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?
- $wpdb working with ajax but showing ajax error instead of success
- Adding content before the loop in category pages
- admin_notices hook show message all admin pages after plugin activate
- How to define WordPress plugin shortcode globally for multisite?
- how to Include json manifest file in wp plugin
- White page on custom plugin option submit
- 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?
- How to find the origin of a file upload from within wp_handle_upload?
- WP All Import – Execute Imports
- How to set taxonomy in custom plugin?
- Plugin development: Buggy plugin preview
- how to use in custom single.php template using php?
- Howto check version of another plugin and then add a submenu page to it
- Which file of wordpress manage plugins functionalities?
- How can i create page through plugin
- I should enable automatic updates?
- Check if variable is set in filter
- How to add custom table style for table block in gutenberg editor
- Does using `add_action( ‘init’…` cause performance issues?
- How to write “alt” tag in image for wordpress code?
- Issues with a WP plugin menu system
- Different custom templates for product category [closed]
- How to create plugin/ page that reads from database
- Add a “View all” button on WooCommerce product archives pages
- How do I add an options page at the bottom of the list?
- 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?
- A question of etiquette when forking a plugin? [closed]
- how to request a script more than once in wordpress
- 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?
- Gutenberg default attributes are empty when accessing in edit
- 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
- 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
- Adding shortcodes to multiple pages with function
- Getting all woocommerce products from REST API call in plugin
- AJAX update fails for public/non-admin users
- Get a list of Product Categories inside a loop
- WordPress Product Detail and catalog
- WordPress plugin changes not updating
- Create Database Tables on Plugin Activation hook
- What’s the preferred method of writing AJAX-enabled plugins?
- Change page according to fetched GET Parameters
- Shortcode registered from a plugin not recognized
- How to change a specific page to custom page?
- wp_update_post call really slow when official Facebook plugin is installed
- 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
- Allow manage_options capability for specific user only for specific plugin?