0

I need to register a script in one plugin and enqueue it in another. This is not working the way I expect it would. Am I missing something?

Plugin that registers script:

add_action( 'wp_enqueue_scripts', 'my_register_styles' );

function my_register_styles() {
        wp_register_style( 'fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css' );
        //wp_enqueue_style( 'fontawesome' ); // This works when uncommented.
}

Other plugin to enqueue script:

add_action( 'wp_enqueue_scripts', 'other_register_styles' );

function my_register_styles() {
       wp_register_style( 'style', PATH . 'assets/css/style.min.css' );
       wp_enqueue_style( 'style' ); // Working as expected

       wp_enqueue_style( 'fontawesome' ); // Currently not working!
}
1

Prioritize your actions, so the register_style function runs first. (notice the third parameter in the add_action function)

add_action( 'wp_enqueue_scripts', 'other_register_styles', 11 );
function other_register_styles() {
       wp_register_style( 'style', PATH . 'assets/css/style.min.css' );
       wp_enqueue_style( 'style' ); // Working as expected

       wp_enqueue_style( 'fontawesome' ); // Currently not working!
}

The default priority is 10, so you just need to add 11 to other_register_styles.

  • Of course! That works wonderfully. Thank you for catching. – Nathan Powell Aug 21 '15 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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