0

I have created a plugin settings page in the WordPress dashboard menu. I want to include css file for that settings page. How can I do that? I am trying following in my plugin, but it does not include the css file on the plugins settings page:

function my_enqueue_styles() {
    wp_enqueue_style( 'my_plugin', plugins_url('my_plugin/plugin.css') );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_styles' );
0

1 Answer 1

0

Refer documentation Link Scripts Only on a Plugin Administration Screen

    add_action( 'admin_menu', 'my_plugin_admin_menu' );
 function my_plugin_admin_menu() {
        /* Add our plugin submenu and administration screen */
        $page_hook_suffix = add_submenu_page( 'edit.php', // The parent page of this submenu
                                  __( 'My Plugin', 'myPlugin' ), // The submenu title
                                  __( 'My Plugin', 'myPlugin' ), // The screen title
                  'manage_options', // The capability required for access to this submenu
                  'my_plugin-options', // The slug to use in the URL of the screen
                                  'my_plugin_manage_menu' // The function to call to display the screen
                               );

        /*
          * Use the retrieved $page_hook_suffix to hook the function that links our script.
          * This hook invokes the function only on our plugin administration screen,
          * see: http://codex.wordpress.org/Administration_Menus#Page_Hook_Suffix
          */
        add_action('admin_print_scripts-' . $page_hook_suffix, 'my_plugin_admin_scripts');
    }

    function my_plugin_admin_scripts() {
        /* Link our already registered script to a page */
        wp_enqueue_script( 'my-plugin-script' );
    }

    function my_plugin_manage_menu() {
        /* Display our administration screen */
    }

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