Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Can the wp-plugins (Must Use Plugins) URL be targeted for use in functions.php? I have a mu-functions.php file in the mu-plugins folder. One function calls a javascript file (alerts.js) located in example.com/wp-content/mu-plugins/js/. How can I target the mu-plugins folder in my function?

Currently, I am using get_site_url() . '/wp-content/mu-plugins/js/alerts.js',

Although not completely relevant to the question, this is the complete function used to call the javascript file:

function load_my_alerts(){
      wp_register_script( 
        'my_alerts', 
        get_site_url() . '/wp-content/mu-plugins/js/alerts.js', 
        array( 'jquery' )
    );
    wp_enqueue_script( 'my_alerts' );
}
add_action('admin_enqueue_scripts', 'load_my_alerts');
share|improve this question

2 Answers 2

up vote 3 down vote accepted

EDIT: this solution is not a best-practice. Please use the solution submitted by Nathan below!

Use the WPMU_PLUGIN_DIR and WPMU_PLUGIN_URL constants :)

function load_my_alerts(){
    wp_register_script( 
        'my_alerts', 
        WPMU_PLUGIN_URL . '/js/alerts.js', 
        array( 'jquery' )
    );
    wp_enqueue_script( 'my_alerts' );
}
add_action('admin_enqueue_scripts', 'load_my_alerts');
share|improve this answer
    
Thanks. I swear I used that. Maybe I missed the leading slash. –  Travis Pflanz Jan 7 '13 at 23:39

It is not good practice to use constants. For this functionality one should ALWAYS use the plugins_url() function seen here in the codex.

    function load_my_alerts(){

        wp_register_script(
            'my_alerts',
            plugins_url('js/alerts.js'),
            array( 'jquery' )
        );

        wp_enqueue_script( 'my_alerts' );

    }

    add_action('admin_enqueue_scripts', 'load_my_alerts');
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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