The theme_root_uri
filter will allow the URLs returned by get_stylesheet_directory_uri()
and get_template_directory_uri()
to be altered on the fly:
/**
* Filters the URI for themes directory.
*
* @since 1.5.0
*
* @param string $theme_root_uri The URI for themes directory.
* @param string $siteurl WordPress web address which is set in General Options.
* @param string $stylesheet_or_template Stylesheet or template name of the theme.
*/
function wpse_theme_root_uri( $theme_root_uri, $siteurl, $stylesheet_or_template ) {
// $siteurl will be http://sitea.com via get_option( 'siteurl' )
return str_replace( $siteurl, 'http://siteb.com', $theme_root_uri );
}
add_filter( 'theme_root_uri', 'wpse_theme_root_uri', 10, 3 );
The plugins_url
filter will allow the URL returned by plugin_dir_url()
to be altered in a similar fashion:
/**
* Filters the URL to the plugins directory.
*
* @since 2.8.0
*
* @param string $url The complete URL to the plugins directory including scheme and path.
* @param string $path Path relative to the URL to the plugins directory. Blank string
* if no path is specified.
* @param string $plugin The plugin file path to be relative to. Blank string if no plugin
* is specified.
*/
function wpse_plugins_url( $url, $path, $plugin ) {
return str_replace( get_option( 'siteurl' ), 'http://siteb.com', $url );
}
add_filter( 'plugins_url', 'wpse_plugins_url', 10, 3 );
Looking through /wp-includes/link-template.php
, there are quite a few other functions that return URLs, but they can be filtered using the same approach as demonstrated above.
The values for the options siteurl
and home
can be modified on the fly as well:
function wpse_pre_option_siteurl_and_home( $pre_option, $option ) {
return 'http://siteb.com';
}
add_filter( 'pre_option_siteurl', 'wpse_pre_option_siteurl_and_home', 10, 2 );
add_filter( 'pre_option_home', 'wpse_pre_option_siteurl_and_home', 10, 2 );