wordpress通过wp_rewrite函数隐藏主题地址信息

LMS
1.6K+ 10

我是勤劳的搬运工。

不想测试,又怕哪天想用了找不到,又没什么体会啊感触啊可写,所以直接从老外那复制过来随便改了下。

WordPress 论坛经常有这样的建议,Wordpress /wp-content/themes/mytheme/ 这种主题文件夹路径看起来不是很优雅,通WordPress 的 rewrite 函数可以改变目录结构,代码如下。

add_action('generate_rewrite_rules', 'themes_dir_add_rewrites');  
  
function themes_dir_add_rewrites() {  
  $theme_name = next(explode('/themes/', get_stylesheet_directory()));  
  
  global $wp_rewrite;  
  $new_non_wp_rules = array(  
    'css/(.*)'       => 'wp-content/themes/'. $theme_name . '/css/$1',  
    'js/(.*)'        => 'wp-content/themes/'. $theme_name . '/js/$1',  
    'images/wordpress-urls-rewrite/(.*)'    => 'wp-content/themes/'. $theme_name . '/images/wordpress-urls-rewrite/$1',  
  );  
  $wp_rewrite->non_wp_rules += $new_non_wp_rules;  
}  

原文:http://www.hongkiat.com/blog/wordpress-url-rewrite/

THE END

评论 10

  1. 博主知道如何在F12中隐藏主域名吗?

    1. 不明白什么意思,浏览器地址栏就能看的到域名,F12里隐藏又有什么用?

  2. 照这个改了以后会是什么样子呢?

    1. 最好不要改,因为我自己都没试过,不知道最终会是什么东东。

    2. 其实用一个自己的2级域名做cdn更好,这个没有必要。

        1. 代码copy之后要修改引用文件的地址,既然都修改了引用问价的地址还不如直接用cdn的地址。

发表评论

Submit