• 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 multisite this location is much more ideal for me.

    What will be the best replacement for get_template_directory_uri() and get_stylsheet_directory_uri() to get these files? 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, here are three CSS examples:

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • rakesh

    (@rakeshkattamudi)

    The other way to get URL of a website or theme is using get blog info function. For more info please check this link https://codex.ww.wp.xz.cn/Function_Reference/get_bloginfo

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Are the js/css in the mu-plugins folder?

    http://codex.ww.wp.xz.cn/Function_Reference/plugins_url

    Works on mu-plugin folders too 🙂

    Thread Starter AM77

    (@andy277)

    Thanks for your replies. That is interesting, so can I just add a css and javascript directories with js and css files inside them in an mu-plugin, then just add:

    function my_scripts_method() {
    	wp_enqueue_script(
    		'newscript',
    		plugins_url( '/js/my.js' , __FILE__ ),
    		array( 'jquery' )
    	);
    }
    add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
    
    //http://codex.ww.wp.xz.cn/Function_Reference/wp_enqueue_script

    I assumed plugins_url was just for the plugins directory.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Surprisingly not:

    Retrieves the absolute URL to the plugins or mu-plugins directory (without the trailing slash) or, when using the $path argument, to a specific file under that directory.

    That code is much the same as what I use for my CSS 🙂

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

The topic ‘Enqueue files for my multisite setup’ is closed to new replies.