The WordPress Codex points to an extremely simple way to change the URL of the wp-content directory, which is, adding this in wp-config.php:
define( 'WP_CONTENT_URL', 'http://example.com/wp-content');
And that does the job of serving most of the JavaScript and CSS files on my website from the different domain, except two.
http://mywebsite.com/wp-includes/js/comment-reply.js
http://mywebsite.com/wp-includes/js/quicktags.js
The reason is very clear â these JavaScript files are served from within the wp-includes directory, which is not affected by the aforementioned rule.
So, is there a similar or simple method to have them served from example.com
i.e. the domain of my choice? or is unregistering and enqueuing the scripts from a custom URL (done in functions.php) the only way?
Okay, I’ve tried numerous (literally) codes and methods, and failed miserably. So, like I said in the question, the only safe way seems to be re-registering (unregistering and enqueuing) the scripts.
The Scripts:
Should be served from:
Code in functions.php:
As for the code used in wp_localize_script, I got it straight from trunk (you can also get it for your WP version, for example, for WP 3.4, the link would be
http://core.svn.wordpress.org/tags/3.4/wp-includes/media.php
).FAQ: Why is quicktags.js loaded in the front-end in the first place? Because I am using the plugin â Basic Comment Quicktags
I know the question is very old, but I think it may still have the attention of some WordPress fans.
Till now, WordPress didn’t implement a way to define “WP_INCLUDES_URL” like we can define “WP_CONTENT_URL”.
So here is an easy workaround, that would do the trick for scripts loaded from wp-includes, using “script_loader_src” filter:
Of course this code belongs to your functions.php inside your theme.
This filter runs on every script being loaded by WordPress, then the function replaces the old domain with the new one.
In the code above, the following link:
Will be replaced with this link:
The function wp_enqueue_script function has an optional second parameter where you can specify a source.