I'm putting CSS and javascript files in a created directory inside a created directory inside wp-content and my enqueue code is going in an mu-plugin. Due to how I have set-up my wordpress multisite this location is much more ideal for me. So the location of these files are mysite.com/wp-content/uw/

What will be the best replacement for get_template_directory_uri() and get_stylsheet_directory_uri() to get these files?

On http://codex.wordpress.org/Function_Reference/wp_enqueue_script

I saw a pattern that get_template_directory_uri() and get_stylsheet_directory_uri() has the path outside the brackets:

get_stylesheet_directory_uri() . '/js/custom_script.js'

Whilst the url one has the path inside the brackets with File on the outside:

plugins_url( '/js/newscript.js' , __FILE__ ),

I have come up with a few that all work but would like to check if they are using good practices or if any of them are not good ideas:

Using content_url that includes __File__:

function test_enqueue() {
    wp_enqueue_style( 'test', content_url( '/uw/test.css' , __FILE__ ) );
add_action( 'wp_enqueue_scripts', 'test_enqueue' );

Using network_site_url() that includes __File__:

function test_enqueue() {
    wp_enqueue_style( 'test', network_site_url( 'wp-content/uw/test.css' , __FILE__ ) );
add_action( 'wp_enqueue_scripts', 'test_enqueue' );

Using get_template_directory_uri() but then to back out:

function test_enqueue() {
    wp_enqueue_style( 'test', get_template_directory_uri() . '/../../uw/test.css');
add_action( 'wp_enqueue_scripts', 'test_enqueue' );

Thanks in advance.

  • My guess would be content_url(), but I am not confident what does it return in multisite precisely. Don't have one on hand to test.
    – Rarst
    Commented Dec 24, 2014 at 8:59

1 Answer 1


content_url(); seems to be the best option in your case. You want the url of wp-content folder, there is no reason to use other workarounds. Also, accroding with codex, content_url() takes care of current site in a multisite network.

But in your example you are using it a little wrong; content_url() doesn't accept a second parameter. It should be content_url( '/uw/test.css' ).

  • Thanks for your replies, you are right I don't need that __ file__. I'll go with content_url(). By the way what is the _ File_ used for as it doesn't say what it is in codex.wordpress and it uses it when it uses plugins_url. Commented Dec 24, 2014 at 18:22
  • __FILE__ is a PHP oredefined constant and its value is the full path of current PHP file including the file name. See docs. If this answer your question, please mark it as accepted.
    – cybmeta
    Commented Dec 25, 2014 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.