This question already has an answer here:

I tried to update the url/src of the queued $wp_scripts correctly... my aim is to use just relative paths. Therefore I:

  1. loaded the $wp_scripts
  2. replace the domain and
  3. saved the output.

But it seems that is not the correct way to updated this variable. Pls explain me way.

 * Correct all script urls for multiple (alias) domain issue
function update_scripts_urls() {
    global $wp_scripts;

    foreach( $wp_scripts->queue as $handle ) {
        $src = $wp_scripts->registered[$handle]->src;
        $link = parse_url(home_url());
        $domain = $link['scheme'].'://'.$link['host'];
        $src = str_replace($domain, '', $src); // replace domain
        $wp_scripts->registered[$handle]->src = $src;
add_action('wp_enqueue_scripts', 'update_scripts_urls', 101);


It seems like $wp_scrips gets updated but the in the header output it shows still the full script url (eg. <script type='text/javascript' src='http://domain.local/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>)? Does the update happens in the to late?

marked as duplicate by Community Oct 25 '15 at 22:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • script_loader_src filter is the proper way to do this. – Milo Oct 25 '15 at 19:49
  • Thx works like charm! – wittich Oct 25 '15 at 22:20