我已经看过问题的多个版本,并尝试了以下内容来重写我主题中的css / js / images / fonts / plugins网址。
然而,我无法让他们中的任何一个在二十三主题中工作。 我强迫htcaccess显示以下内容但没有运气
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^css/(.*) /wp-content/themes/dfi/css/$1 [QSA,L]
RewriteRule ^images/(.*) /wp-content/themes/dfi/images/$1 [QSA,L]
RewriteRule ^fonts/(.*) /wp-content/themes/dfi/fonts/$1 [QSA,L]
RewriteRule ^js/(.*) /wp-content/themes/dfi/js/$1 [QSA,L]
RewriteRule ^plugins/(.*) /wp-content/plugins/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
我在主题
的functions.php文件中尝试了这个 // rewrite /wp-content/themes/theme-name/css/ to /css/
// rewrite /wp-content/themes/theme-name/js/ to /js/
// rewrite /wp-content/themes/theme-name/img/ to /img/
// rewrite /wp-content/plugins/ to /plugins/
function roots_flush_rewrites() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
function roots_add_rewrites($content) {
$theme_name = next(explode('/themes/', get_stylesheet_directory()));
global $wp_rewrite;
$roots_new_non_wp_rules = array(
'css/(.*)' => 'wp-content/themes/'. $theme_name . '/css/$1',
'js/(.*)' => 'wp-content/themes/'. $theme_name . '/js/$1',
'img/(.*)' => 'wp-content/themes/'. $theme_name . '/img/$1',
'plugins/(.*)' => 'wp-content/plugins/$1'
);
$wp_rewrite->non_wp_rules += $roots_new_non_wp_rules;
}
add_action('admin_init', 'roots_flush_rewrites');
function roots_clean_assets($content) {
$theme_name = next(explode('/themes/', $content));
$current_path = '/wp-content/themes/' . $theme_name;
$new_path = '';
$content = str_replace($current_path, $new_path, $content);
return $content;
}
function roots_clean_plugins($content) {
$current_path = '/wp-content/plugins';
$new_path = '/plugins';
$content = str_replace($current_path, $new_path, $content);
return $content;
}
和其他几个无济于事。任何人都可以告诉我我缺少什么(代码)或这个代码应该去哪里?
非常感谢!答案 0 :(得分:0)
尝试此解决方案:: http://www.hongkiat.com/blog/wordpress-url-rewrite/
如果您正在使用root starter主题,请查看此插件http://roots.io/plugins/roots-rewrites/