这个theme_root_uri
筛选器将允许返回的URLget_stylesheet_directory_uri()
和get_template_directory_uri()
要即时更改:
/**
* 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
筛选器将允许返回的URL
plugin_dir_url()
以类似方式更改:
/**
* 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 );
正在查看
/wp-includes/link-template.php
, 有很多其他函数返回URL,但可以使用与上面演示的相同方法对其进行过滤。
选项的值siteurl
和home
也可以动态修改:
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 );