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 );
}