Filter script_loader_src
and use add_query_arg()
. You can use parse_url()
or the second argument $handle
to target specific scripts…
I have included multiple redundant options here:
add_filter( 'script_loader_src', 'wpse_99842_add_get_var_to_url', 10, 2 );
function wpse_99842_add_get_var_to_url( $url, $handle )
{
if ( 'my_handle' !== $handle )
return $url;
if ( empty ( $_GET['myvar'] ) )
return $url;
$parts = parse_url( $url );
// specific host
if ( 'example.com' !== $parts['host'] )
return $url;
// specific path
if ( '/foo/bar' !== $parts['path'] )
return $url;
// or specific start of path
if ( 0 !== strpos( $parts['path'], '/foo/' ) )
return $url;
return add_query_arg( 'myVar', $_GET['myvar'], $url );
}
Related Posts:
- Add a script as a dependency to a registered script
- Register scripts located in child theme?
- How to properly dequeue scripts and styles in child theme?
- Correct Method to run scripts with dependencies without enqueue?
- Setting up an API “listening” page
- wp_register_script multiple identifiers?
- Serving wp-includes (front-end) javascript from a different domain?
- wp_enqueue_script with dependencies doesn’t work
- Help with enqueing scripts in footer after init action
- Add conversion/tracking pixel to section for specific post
- Question about the way that wp_register_script works
- How can I selectively print scripts to the footer of certain admin pages?
- How to cancel `wp_print_scripts`?
- WP CLI theme install. Install a private repo?
- change $src from wp_register_script in plugins/themes
- Why won’t my scripts load?
- By having WordPress in a subfolder does it mean more script executions?
- Script Code in Text Widget Does NOT Show
- Invision + WordPress integration
- wp_print_scripts runs twice
- How to serve wp-includes javascripts from CDN? [duplicate]
- Generating a static page from a script
- Refused to execute as script because “X-Content-Type: nosniff” was given and its Content-Type is not a script MIME type
- How to get, in WP page’s script, a wp enqueued script (in Functions.php)?
- Disable load scripts and styles not working
- Socialite not displaying icons [closed]
- Script dependencies generates different outputs
- Renaming the ‘build’ directory generated by @wordpress/scripts for React development
- How to defer block.json scripts?
- How do I make it so that wp-scripts builds on plugin activation
- Enqueue Scripts / Styles when shortcode is present
- When should I use wp_register_script() with wp_enqueue_script() vs just wp_enqueue_script()?
- Where is the right place to register/enqueue scripts & styles
- What is your best practice to execute one-time scripts?
- Check if a script/style was enqueued/registered
- How do I get the $handle for all enqueued scripts?
- How can I get a list of all enqueued scripts and styles?
- Conditionally enqueue a widget’s script/stylesheet in HEAD (only when present on page!)
- What are the benefits of using wp_enqueue_script?
- wp_enqueue_scripts, wp_register_scripts, wp_print_scripts: i’m confused
- How can I create a bash install script for my WordPress sites setup (WP+plugins+theme)?
- Remove ?ver= from wp_register_script
- Register and enqueue conditional (browser-specific) javascript files?
- Cannot deregister a script using wp_deregister_script
- dynamically add scripts to WP_Widget widget() method
- Load js/css files only on specific admin UI pages
- Load plugin scripts and styles only on plugin page
- Get list of scripts / styles and show file which enqueued them
- How to prevent wordpress from loading old versions of jquery in wp_head();?
- How to dequeue / deregister any theme styles and scripts
- Is it possible to change the attributes of a registered style or script before it fires?
- Enqueue script only when shortcode is used, with WP Plugin Boilerplate
- Hyphens vs. periods in the script slug in wp_register_script?
- How to get a jQuery script to run on a page?
- Outputting Canonical Resource URLs Across a Multisite Network?
- Editing Source Code in WordPress
- How to load JQuery easing script in wordpress?
- Odd Script File Trying to be Loaded
- Listing registered scripts
- enqueue and localize script in footer
- How to disable hoverIntent in WordPress 3.3 admin
- Some way to Flush or Overwrite all Imported Content in a Site for a Fresh Import – How?
- enqueuing React script and hooking its target div fails to load script
- Shortest possible shell script to install WordPress on Nginx server?
- Including javascript for a shortcode
- Trigger a php file on every post or page if a condition is met
- How do I load custom scripts and styles for a page?
- Most elegant way to enqueue scripts in function.php with foreach loop
- wp_register_script was called incorrectly
- How to Add a Custom Script to Customize.php
- wp_enqueue_script vs. wp_register_script
- How do I enqueue(or delay loading of) tags in individual page posts?
- Adding scripts to admin page in my theme
- Use js script from one plugin in another plugin
- Pass $this to function nested in another public function of the same class
- Child Theme – what is the scope of overwriting files?
- Best way to enqueue extremely popular scripts like bootstrap and font awesome
- Styles and Scripts, Selectively enqueue across entire site
- How to remove some external js files from source?
- Dequeue / Deregister script and replace it with a new plugin
- Best way to create a user programatically
- Why Allow Script Commands in Comments?
- WP deregister, register and enqueue dequeue
- WordPress Script Loading/Unloading — wp_deregister_script(‘jquery’)
- Is it possible to add an action to the currently running action?
- Adding jQuery dependency prevents my script from enqueuing/loading
- Best spot for wp_register_script() and wp_register_style()
- How does WordPress create its database during installation?
- Is there any free (or cheap) software that can be used for testing WordPress functionality?
- Select2 in WordPress
- Unable to load stylesheets and scripts to plugin settings page
- Can’t get JS code to work with shortcode
- How can I add my script to admin using script-loader.php?
- Disable unneeded scripts in a wordpress installation
- wp_enqueue_script adds only the first script
- changing function wp_register
- Register script/style: Is it possible to customize the version query string via plugin?
- Javascript code inside “” in core WordPress files .php
- How to properly add Bootstrap and JQuery Javascripts?
- How resource intensive is wp_register_script()?