我想你需要两件事:
首先,您的中的重写规则。htaccess文件如下:
RewriteEngine On
RewriteBase /
RewriteRule ^css/(.*) /wp-content/themes/theme-name/css/$1 [L]
RewriteRule ^js/(.*) /wp-content/themes/theme-name/js/$1 [L]
其次,为主题的函数添加一个过滤器。php类似:
function change_css_js_url($content) {
$current_path = \'/wp-content/themes/theme-name/\';
$new_path = \'/\'; // No need to add /css or /js here since you\'re mapping the subdirectories 1-to-1
$content = str_replace($current_path, $new_path, $content);
return $content;
}
add_filter(\'bloginfo_url\', \'change_css_js_url\');
add_filter(\'bloginfo\', \'change_css_js_url\');
有几个注意事项:-如果插件或其他东西不使用bloginfo()或get\\u bloginfo(),则不会触发过滤器。您可以根据需要将您的函数挂接到其他过滤器中来绕过此问题。-一些插件/主题/等使用硬编码路径。除了修改代码以使用WP的一个函数来获取路径之外,您对此无能为力。
下面是使用twentyten主题的相同示例(没有css/js子目录,但想法是一样的)
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^twentyten/(.*) /wp-content/themes/twentyten/$1 [L]
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
functions.php
function change_css_js_url($content) {
$current_path = \'/wp-content/themes/\';
$new_path = \'/\'; // No need to add /css or /js here since you\'re mapping the subdirectories 1-to-1
$content = str_replace($current_path, $new_path, $content);
return $content;
}
add_filter(\'bloginfo_url\', \'change_css_js_url\');
add_filter(\'bloginfo\', \'change_css_js_url\');