public
Last active

Hide wp-content/themes path

  • Download Gist
wpse_76593.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
<?php
// REMOVE WP-CONTENT
// Rewrites DO NOT happen for child themes
// Add .htaccess rewrite rules to convert urls
// like "http://example.com/wp-content/themes/theme-name/path" into "http://example.com/path"
 
/*
in case your wordpress is in a folder,
and you change the site_url to the root of the domain,
add the folder name in lines 29 to 34,
i.e.: => 'YOUR-WP-FOLDER/wp-content/themes/'
*/
if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) {
function roots_htaccess_writable() {
if (!is_writable(get_home_path() . '.htaccess')) {
add_action('admin_notices', create_function('', "echo '<div class=\"error\"><p>" . sprintf(__('Please make sure your <a href="%s">.htaccess</a> file is writeable ', 'roots'), admin_url('options-permalink.php')) . "</p></div>';"));
};
}
 
add_action('admin_init', 'roots_htaccess_writable');
 
 
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',
'framework/(.*)' => 'wp-content/themes/'. $theme_name . '/framework/$1',
'images/(.*)' => 'wp-content/themes/'. $theme_name . '/images/$1',
'uploads/(.*)' => 'wp-content/uploads/$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;
}
 
// only use clean urls if the theme isn't a child or an MU (Network) install
if (!is_multisite() && !is_child_theme()) {
add_action('generate_rewrite_rules', 'roots_add_rewrites');
if (!is_admin()) {
add_filter('plugins_url', 'roots_clean_plugins');
add_filter('bloginfo', 'roots_clean_assets');
add_filter('stylesheet_directory_uri', 'roots_clean_assets');
add_filter('template_directory_uri', 'roots_clean_assets');
add_filter('script_loader_src', 'roots_clean_plugins');
add_filter('style_loader_src', 'roots_clean_plugins');
}
}
 
function roots_add_h5bp_htaccess($rules) {
global $wp_filesystem;
 
if (!defined('FS_METHOD')) define('FS_METHOD', 'direct');
if (is_null($wp_filesystem)) WP_Filesystem(array(), ABSPATH);
if (!defined('WP_CONTENT_DIR'))
define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
 
$theme_name = next(explode('/themes/', get_template_directory()));
$filename = WP_CONTENT_DIR . '/themes/' . $theme_name . '/inc/h5bp-htaccess';
 
$rules .= $wp_filesystem->get_contents($filename);
return $rules;
}
 
add_action('mod_rewrite_rules', 'roots_add_h5bp_htaccess');
}
 
if (!is_admin()){
wp_deregister_script('l10n');
}

Hello, Please where can I add this code

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.