Search code examples
csswordpresspluginswp-enqueue-scripts

Wordpress Plugin CSS style sheet shows up correctly in some themes but not others


I'm writing a custom wordpress plugin, and am trying to enqueue the plugin's CSS style. Currently testing in my local WP instance.

  1. The styling is partially working in the Twenty Twenty Two theme (the dashicons are showing correctly, style doesn't work),
  2. is not working in the Twenty Twenty theme (neither dashicons nor style are showing up),
  3. but it is working properly in the Twenty Twenty One theme.

Here is the code:

function comment_rating_styles() {

    wp_register_style( 'comment-rating-styles', plugins_url( '/' , __FILE__ ) . 'assets/style.css');

    wp_enqueue_style( 'dashicons' );
    wp_enqueue_style( 'comment-rating-styles' );
}

add_action( 'wp_enqueue_scripts', 'comment_rating_styles' );

Solution

  • It may be possible that something in the theme overwrites or disables the dashicons or the comment styles. You can try to add a higher priority, so it gets executed later.

    add_action( 'wp_enqueue_scripts', 'comment_rating_styles', 999 );