0

I'm trying to add a stylesheet for my plugin class settings page, but the CSS is not loading. I followed the 2nd example at http://codex.wordpress.org/Function_Reference/wp_register_style to create this simple test code :

class MyTestPlugin
{
    public function __construct() 
    {
            add_action('admin_menu', array($this, 'add_menu'));
            add_action( 'wp_enqueue_scripts', array($this, 'register_plugin_styles' ));
    }
    public function register_plugin_styles() {
            wp_register_style( 'my-test-plugin', plugins_url('sbm-test.css', __FILE__) );
            wp_enqueue_style('my-test-plugin');
    }
    public function add_menu()
    {
            add_options_page('SBM Test Settings', 'SBM Test', 'manage_options', 'sbm-test', array($this, 'sbm_test_options'));
    }
    public function sbm_test_options()
    {
            echo "<p>SBM Test Options Page.</p>"; 
            echo "<p>" .  plugins_url('sbm-test.css', __FILE__) . " is not loaded.</p>";
    }
}

if(class_exists('MyTestPlugin'))
{
    $test = new MyTestPlugin();
}

The path to sbm-test.css is correct, but I think the function register_plugin_styles isn't being called. I have WP_DEBUG_LOG true but not seeing any errors in the log. I'm not sure why add_action isn't hooking it in so I'm hoping someone sees something I missed.

6

IF you want the CSS to be in your plugin's settings page, you should be using this action: admin_enqueue_scripts, as the action you are currently using is for the front end.

add_action( 'admin_enqueue_scripts', array($this, 'register_plugin_styles' ));

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.