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?
- 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)?
- Register and enqueue conditional (browser-specific) javascript files?
- Editing Source Code in WordPress
- How to load JQuery easing script in wordpress?
- Listing registered scripts
- How do I load custom scripts and styles for a page?
- Most elegant way to enqueue scripts in function.php with foreach loop
- 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?
- Best way to create a user programatically
- Why Allow Script Commands in Comments?
- How does WordPress create its database during installation?
- How to properly add Bootstrap and JQuery Javascripts?
- Can’t move jQuery to footer
- Using multiple versions of jQuery while still calling it like WP likes
- Naming script handles right way
- How do I get a child theme to load scripts from the parent theme?
- How do I enqueue a JavaScript in my footer via the functions.php file?
- Including style.css in Child Theme
- Deregistering a script in WordPress seems impossible
- Change directory of javascript files
- Correct check for any admin page with editor
- Is there a way to list all the JavaScript scripts that are actually loaded by WordPress? Do we care?
- How to force that styles are enqueued in the header?
- Styles and scripts inside template part
- I can’t enqueue my scripts – They literally aren’t being added to my site
- How to load library scripts in admin from plugins in noConflict wrapper?
- Where is the right place to register/enqueue scripts & styles
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- Deregister multiple scripts using a function?
- wp_enqueue_script was called incorrectly Issue when active plugins of WordPress Admin Bar Improved
- wp_enqueue_scripts does not work
- Modular CSS and JS in Child Themes
- If a Script has been enqueued but not registered can I still removed it?
- include jquery plugin file not working
- Starting with tabbed metabox
- How to use wp_register_script / wp_enqueue_script for multiple queries
- WordPress url transformation script
- How to use custom Javascript code inside a plugin?
- Automatic WordPress Clone Backup
- Order of WP page load (including widgets, php, plugins, media, templates, and CSS) [duplicate]
- jQuery plugin not loading
- Register through url
- What’s the default setting for including a in a post
- Running xDebug and NPM at the same time?
- Moving Javascript from footer to header
- Can’t load a script in my plugin page
- How to force one script to load before google tag manager script
- Media Library Cleanup A Thought Exercise
- How to add the google ad conversion tracking code into the thank you page
- How do you enable scripts on a WordPress installation in Softaculous?
- Enabling plugin on specific pages and subpages
- bundled jquery in theme js not working with wp_localize_script
- How to redirect new registrars to a custom registration page instead of WP default registration page?
- style.min.css code issue
- Enqueued admin javascript for plugin settings page not executing
- How to change text in a page by utilizing a custom user id?
- Editing existing pre-created menus in PHP
- How to wp_enqueue_script with html?
- Domain mapping breaks some plugin scripts and css
- WordPress menus – automatically generate
- Plugin’s required JS not being inserted in my theme
- can’t access dashboard and showing forbidden page
- wp_deregister_script was called incorrectly
- Need help with adding jQuery script to WP and calling script to page
- Adding css and js to a blank page created with custom template
- Enqueue scripts in the footer
- Change color of a specific word generated by script [closed]
- Loading newest dependency javascript module file in functions.php