样式Wordpress插件设置页面

时间:2015-11-17 12:58:55

标签: php wordpress

我已经为wordpress创建了一个插件,我现在正在管理区域的设置页面上工作,如何添加一个样式表

插件/ pluginname /资产/ CSS / bootstrap.min.css

1 个答案:

答案 0 :(得分:0)

在这里找到解决方案: https://codex.wordpress.org/Function_Reference/wp_enqueue_style

仅在插件的选项页面上加载样式表

   /*
    * This example will work at least on WordPress 2.6.3, 
    * but maybe on older versions too.
    */
   add_action( 'admin_init', 'my_plugin_admin_init' );
   add_action( 'admin_menu', 'my_plugin_admin_menu' );

   function my_plugin_admin_init() {
       /* Register our stylesheet. */
       wp_register_style( 'myPluginStylesheet', plugins_url('stylesheet.css', __FILE__) );
   }

   function my_plugin_admin_menu() {
       /* Register our plugin page */
       $page = add_submenu_page( 'edit.php', 
                                 __( 'My Plugin', 'myPlugin' ), 
                                 __( 'My Plugin', 'myPlugin' ),
                                 'administrator',
                                 __FILE__, 
                                 'my_plugin_manage_menu' );

       /* Using registered $page handle to hook stylesheet loading */
       add_action( 'admin_print_styles-' . $page, 'my_plugin_admin_styles' );
   }

   function my_plugin_admin_styles() {
       /*
        * It will be called only on your plugin admin page, enqueue our stylesheet here
        */
       wp_enqueue_style( 'myPluginStylesheet' );
   }

   function my_plugin_manage_menu() {
       /* Output our admin page */
   }