• Resolved jessetr

    (@jessetr)


    I recently downloaded and installed the Roots Theme (rootstheme.com) which does some very interesting things. One feature is that, after you load a WordPress page, the links to the CSS, JS and IMG files appear to be stored in the root folder of the site (for example http://site.com/css/style.css instead of http://site.com/wp-content/themes/theme-name/css/style.css).

    I believe this involves editing the .htaccess files and the functions.php file. The Roots Theme does a whole bunch of other things which I don’t need/want. Can someone help me enable this feature on my own custom theme? Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Just dig through the Roots Theme code, and you’ll find it. Actually, if I remember correctly, that Theme has very extensive documentation on its website; so I’d start there.

    It considers that static-resource URL rewriting to be a “feature”; personally, I disagree. I think it’s entirely pointless, and wasted resources.

    Thread Starter jessetr

    (@jessetr)

    Rather than arguing about why, I’d rather people respond with how. I think it’s useful for people who want to hide the fact that the site is built on WordPress. The roots theme does lots of things, I’m only interested in this one thing and I have yet to get this to work without using the entire theme. Please help.

    Start here:
    https://github.com/retlehs/roots/wiki

    Here is the function-specific documentation:
    https://github.com/retlehs/roots/wiki/Roots-functions

    The documentation indicates that URL rewrites are defined in:
    inc/roots-cleanup.php

    Here’s the source of inc/roots-cleanup.php:
    https://github.com/retlehs/roots/blob/master/inc/roots-cleanup.php

    And in that file, here is the function that defines the rewrites:

    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');

    Thread Starter jessetr

    (@jessetr)

    Thanks for the help. Finally got it working using the code below. Had to install Roots Theme to see what the final .htaccess file looked like to pull the code. This is what I came up with for anyone else interested, obviously changing the theme folder name “realnice” to whatever you’re using:

    Functions.php

    [Code moderated as per the Forum Rules. Please use the pastebin]

    @jessetr
    could you kindly post your code again in pastebin?

    thanks

    Thread Starter jessetr

    (@jessetr)

    Here’s a link to Pastebin. I’ve never used it before. Let me know if you need anything else.

    Pastebin link.

    thanks, mate!
    i’ve been studying Chip Bennett’s links, and will post results and code afterwards

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Visible Path to CSS/JS files’ is closed to new replies.