• Resolved Azumi93

    (@azumi93)


    Hello,

    I am trying to link CSS styles to my plugin. The styles are for the _/settings_ of the plugin. It is just styling of the settings form.

    add_action('admin_enqueue_scripts', 'emnoti_styles');

    ^^ I link the styles there in the index.php and in functions.php I have this function:

    
    function emnoti_styles() {
        wp_register_style( 'the_plugin_css', 'styles/emnoti_styles.css' );
        wp_enqueue_style( 'the_plugin_css' );
    }
    

    But the styles aren’t applied. There is no error, just no styling. Please tell me what I am doing wrong. Thank you!

    • This topic was modified 6 years, 2 months ago by Azumi93.
    • This topic was modified 6 years, 2 months ago by Azumi93.
    • This topic was modified 6 years, 2 months ago by Steven Stern (sterndata).
    • This topic was modified 6 years, 2 months ago by Azumi93.
    • This topic was modified 6 years, 2 months ago by Azumi93.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Is this index.php part of your plugin? Is the functions.php part of your plugin?
    The function should be part of the plugin, and the action to hook to in order to load the styles should be related to when your settings page is shown. The styles should not be loaded for every admin page.
    Also, the path to the styles needs to be a complete path, not relative.

    Thread Starter Azumi93

    (@azumi93)

    ^^ Thank you so much, Joy!

    I changed add_action('admin_enqueue_scripts', 'emnoti_styles'); to add_action('admin_init', 'emnoti_styles'); and wp_register_style( 'the_plugin_css', 'styles/emnoti_styles.css' ); to wp_register_style( 'the_plugin_css', plugins_url('styles/emnoti_styles.css', __FILE__) ); and it worked!

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can’t link CSS to plugin’ is closed to new replies.