0

I'm in Wordpress 4.5.2 on Windows 10 and I'm trying to register and enqueue my stylesheet in Wordpress, but it just isn't working. I'm having the same problem with jQuery.

I have this code in a plugin, and I am displaying a dashboard widget, which is working just fine:

<?php
    /*
     *   Plugin Name: TEST PLUGIN
    */

    /*  register styles and scripts
    *   register dash widgets
    *
    */

    function register_styles() {

        wp_register_script( 'wildstyle', plugins_url('css/wildstyle.css', __FILE__ ) );

        wp_enqueue_script( 'wildstyle' );
    }

    function register_dash_widget() {

        wp_add_dashboard_widget(
             'test-widget',
             'Test Widget',
             'display_callback'
        );
    }

    /*  add all the actions
    *   
    *
    */

    add_action( 'wp_enqueue_scripts', 'register_styles' );
    add_action( 'wp_dashboard_setup', 'register_dash_widget' );

    /*  display callback for dashboard metabox
    *
    *
    */

    function display_callback() {

        echo '<p>Testing, testing...</p>';
    }

Here is the little bit of css that I'm using for the test:

p {
    color: red;
}

Why is my text not red?

2 Answers 2

2

You can add stylesheet in back-office, but you need for that use the admin_enqueue_scripts action.

See Codex reference : https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts

3
  • Awesome. That worked, thanks. I also needed to use wp_register_style/wp_register_script in register_styles().
    – Dan Luba
    Jun 19, 2016 at 0:20
  • In this hook you can also add style or script. This is your quest ?
    – Gregcta
    Jun 19, 2016 at 0:22
  • It wasn't a question, I was just adding some extra info for anyone else who might come across this question. Just using admin_enqueue_scripts didn't work, at first, but when I changed wp_enqueue_script to wp_enqueue_style (and the same with register), it worked. Thanks again.
    – Dan Luba
    Jun 19, 2016 at 0:32
0

Just change both lines:

wp_register_script( 'wildstyle', plugins_url('css/wildstyle.css', __FILE__ ) );
wp_enqueue_script( 'wildstyle' );

to

wp_register_style( 'wildstyle', plugins_url('css/wildstyle.css', __FILE__ ) );
wp_enqueue_style( 'wildstyle' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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