Use my custom CSS just for my WordPress plugin settings page, how?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















I'm developing my first WordPress plugin. I need to use a custom CSS for the settings pages that I created for the plugin but when I enqueue my stylesheet file, it affects the whole WordPress backend and not just my plugin's settings page.
Is possible to solve this problem? How?










share|improve this question





























    -1















    I'm developing my first WordPress plugin. I need to use a custom CSS for the settings pages that I created for the plugin but when I enqueue my stylesheet file, it affects the whole WordPress backend and not just my plugin's settings page.
    Is possible to solve this problem? How?










    share|improve this question

























      -1












      -1








      -1








      I'm developing my first WordPress plugin. I need to use a custom CSS for the settings pages that I created for the plugin but when I enqueue my stylesheet file, it affects the whole WordPress backend and not just my plugin's settings page.
      Is possible to solve this problem? How?










      share|improve this question














      I'm developing my first WordPress plugin. I need to use a custom CSS for the settings pages that I created for the plugin but when I enqueue my stylesheet file, it affects the whole WordPress backend and not just my plugin's settings page.
      Is possible to solve this problem? How?







      css wordpress plugins






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 13:50









      icolumbroicolumbro

      175




      175
























          1 Answer
          1






          active

          oldest

          votes


















          0














          When you want to add styles or scripts in WordPress you enqueue them using hooks. For the admin side the hook you are looking for is called admin_enqueue_scripts.



          You can add something like



          /**
          * Register and enqueue a custom stylesheet in the WordPress admin.
          */
          function wpdocs_enqueue_custom_admin_style() {
          wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
          wp_enqueue_style( 'custom_wp_admin_css' );
          }

          add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );


          You just need to be careful to correctly specify the url of the css script you want to enqueue.



          Hope this helps.



          Oh and https://developer.wordpress.org page is great for finding out about WordPress functionality, core functions, hooks etc.



          Also check out the plugin handbook: https://developer.wordpress.org/plugins/
          Loads of useful information can be found there :)



          EDIT:



          admin_enqueue_scripts has a parameter you can use read more



          /**
          * Register and enqueue a custom stylesheet in the WordPress admin.
          */
          function wpdocs_enqueue_custom_admin_style( $hook ) {
          if ( $hook === 'edit.php' ) {
          wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
          wp_enqueue_style( 'custom_wp_admin_css' );
          }
          }

          add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );


          This will load the script only on the edit post screen.



          You can see what hook is loaded on your screen by adding



          error_log( print_r( $hook, true ) );


          In your wpdocs_enqueue_custom_admin_style function before the condition. Enable the debug log in your wp-config.php and you'll get a name of your custom post screen hook.



          Alternatively, you could target the $current_screen to match the CPT's screen. This will load the script only on that page.






          share|improve this answer


























          • Thank you for reply but I know I must use admin_enqueue_scripts hook and wp_enqueue_style function but the problem is that doing this my CSS style affects whole admin side not my plugin settings pages only. E.g.: if in my CSS I write h1 { color: red; } every h1 tag shows in red and not just the h1 tags in my plugin pages...

            – icolumbro
            Nov 24 '18 at 15:06











          • As noted in the docs, you can pass a $hook argument and then see on what page you want your script to load :)

            – dingo_d
            Nov 25 '18 at 10:01












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458820%2fuse-my-custom-css-just-for-my-wordpress-plugin-settings-page-how%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          When you want to add styles or scripts in WordPress you enqueue them using hooks. For the admin side the hook you are looking for is called admin_enqueue_scripts.



          You can add something like



          /**
          * Register and enqueue a custom stylesheet in the WordPress admin.
          */
          function wpdocs_enqueue_custom_admin_style() {
          wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
          wp_enqueue_style( 'custom_wp_admin_css' );
          }

          add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );


          You just need to be careful to correctly specify the url of the css script you want to enqueue.



          Hope this helps.



          Oh and https://developer.wordpress.org page is great for finding out about WordPress functionality, core functions, hooks etc.



          Also check out the plugin handbook: https://developer.wordpress.org/plugins/
          Loads of useful information can be found there :)



          EDIT:



          admin_enqueue_scripts has a parameter you can use read more



          /**
          * Register and enqueue a custom stylesheet in the WordPress admin.
          */
          function wpdocs_enqueue_custom_admin_style( $hook ) {
          if ( $hook === 'edit.php' ) {
          wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
          wp_enqueue_style( 'custom_wp_admin_css' );
          }
          }

          add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );


          This will load the script only on the edit post screen.



          You can see what hook is loaded on your screen by adding



          error_log( print_r( $hook, true ) );


          In your wpdocs_enqueue_custom_admin_style function before the condition. Enable the debug log in your wp-config.php and you'll get a name of your custom post screen hook.



          Alternatively, you could target the $current_screen to match the CPT's screen. This will load the script only on that page.






          share|improve this answer


























          • Thank you for reply but I know I must use admin_enqueue_scripts hook and wp_enqueue_style function but the problem is that doing this my CSS style affects whole admin side not my plugin settings pages only. E.g.: if in my CSS I write h1 { color: red; } every h1 tag shows in red and not just the h1 tags in my plugin pages...

            – icolumbro
            Nov 24 '18 at 15:06











          • As noted in the docs, you can pass a $hook argument and then see on what page you want your script to load :)

            – dingo_d
            Nov 25 '18 at 10:01
















          0














          When you want to add styles or scripts in WordPress you enqueue them using hooks. For the admin side the hook you are looking for is called admin_enqueue_scripts.



          You can add something like



          /**
          * Register and enqueue a custom stylesheet in the WordPress admin.
          */
          function wpdocs_enqueue_custom_admin_style() {
          wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
          wp_enqueue_style( 'custom_wp_admin_css' );
          }

          add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );


          You just need to be careful to correctly specify the url of the css script you want to enqueue.



          Hope this helps.



          Oh and https://developer.wordpress.org page is great for finding out about WordPress functionality, core functions, hooks etc.



          Also check out the plugin handbook: https://developer.wordpress.org/plugins/
          Loads of useful information can be found there :)



          EDIT:



          admin_enqueue_scripts has a parameter you can use read more



          /**
          * Register and enqueue a custom stylesheet in the WordPress admin.
          */
          function wpdocs_enqueue_custom_admin_style( $hook ) {
          if ( $hook === 'edit.php' ) {
          wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
          wp_enqueue_style( 'custom_wp_admin_css' );
          }
          }

          add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );


          This will load the script only on the edit post screen.



          You can see what hook is loaded on your screen by adding



          error_log( print_r( $hook, true ) );


          In your wpdocs_enqueue_custom_admin_style function before the condition. Enable the debug log in your wp-config.php and you'll get a name of your custom post screen hook.



          Alternatively, you could target the $current_screen to match the CPT's screen. This will load the script only on that page.






          share|improve this answer


























          • Thank you for reply but I know I must use admin_enqueue_scripts hook and wp_enqueue_style function but the problem is that doing this my CSS style affects whole admin side not my plugin settings pages only. E.g.: if in my CSS I write h1 { color: red; } every h1 tag shows in red and not just the h1 tags in my plugin pages...

            – icolumbro
            Nov 24 '18 at 15:06











          • As noted in the docs, you can pass a $hook argument and then see on what page you want your script to load :)

            – dingo_d
            Nov 25 '18 at 10:01














          0












          0








          0







          When you want to add styles or scripts in WordPress you enqueue them using hooks. For the admin side the hook you are looking for is called admin_enqueue_scripts.



          You can add something like



          /**
          * Register and enqueue a custom stylesheet in the WordPress admin.
          */
          function wpdocs_enqueue_custom_admin_style() {
          wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
          wp_enqueue_style( 'custom_wp_admin_css' );
          }

          add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );


          You just need to be careful to correctly specify the url of the css script you want to enqueue.



          Hope this helps.



          Oh and https://developer.wordpress.org page is great for finding out about WordPress functionality, core functions, hooks etc.



          Also check out the plugin handbook: https://developer.wordpress.org/plugins/
          Loads of useful information can be found there :)



          EDIT:



          admin_enqueue_scripts has a parameter you can use read more



          /**
          * Register and enqueue a custom stylesheet in the WordPress admin.
          */
          function wpdocs_enqueue_custom_admin_style( $hook ) {
          if ( $hook === 'edit.php' ) {
          wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
          wp_enqueue_style( 'custom_wp_admin_css' );
          }
          }

          add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );


          This will load the script only on the edit post screen.



          You can see what hook is loaded on your screen by adding



          error_log( print_r( $hook, true ) );


          In your wpdocs_enqueue_custom_admin_style function before the condition. Enable the debug log in your wp-config.php and you'll get a name of your custom post screen hook.



          Alternatively, you could target the $current_screen to match the CPT's screen. This will load the script only on that page.






          share|improve this answer















          When you want to add styles or scripts in WordPress you enqueue them using hooks. For the admin side the hook you are looking for is called admin_enqueue_scripts.



          You can add something like



          /**
          * Register and enqueue a custom stylesheet in the WordPress admin.
          */
          function wpdocs_enqueue_custom_admin_style() {
          wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
          wp_enqueue_style( 'custom_wp_admin_css' );
          }

          add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );


          You just need to be careful to correctly specify the url of the css script you want to enqueue.



          Hope this helps.



          Oh and https://developer.wordpress.org page is great for finding out about WordPress functionality, core functions, hooks etc.



          Also check out the plugin handbook: https://developer.wordpress.org/plugins/
          Loads of useful information can be found there :)



          EDIT:



          admin_enqueue_scripts has a parameter you can use read more



          /**
          * Register and enqueue a custom stylesheet in the WordPress admin.
          */
          function wpdocs_enqueue_custom_admin_style( $hook ) {
          if ( $hook === 'edit.php' ) {
          wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'css/woo-solo-api-admin.css', false, '1.0.0' );
          wp_enqueue_style( 'custom_wp_admin_css' );
          }
          }

          add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );


          This will load the script only on the edit post screen.



          You can see what hook is loaded on your screen by adding



          error_log( print_r( $hook, true ) );


          In your wpdocs_enqueue_custom_admin_style function before the condition. Enable the debug log in your wp-config.php and you'll get a name of your custom post screen hook.



          Alternatively, you could target the $current_screen to match the CPT's screen. This will load the script only on that page.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 25 '18 at 10:04

























          answered Nov 24 '18 at 13:57









          dingo_ddingo_d

          6,27794885




          6,27794885













          • Thank you for reply but I know I must use admin_enqueue_scripts hook and wp_enqueue_style function but the problem is that doing this my CSS style affects whole admin side not my plugin settings pages only. E.g.: if in my CSS I write h1 { color: red; } every h1 tag shows in red and not just the h1 tags in my plugin pages...

            – icolumbro
            Nov 24 '18 at 15:06











          • As noted in the docs, you can pass a $hook argument and then see on what page you want your script to load :)

            – dingo_d
            Nov 25 '18 at 10:01



















          • Thank you for reply but I know I must use admin_enqueue_scripts hook and wp_enqueue_style function but the problem is that doing this my CSS style affects whole admin side not my plugin settings pages only. E.g.: if in my CSS I write h1 { color: red; } every h1 tag shows in red and not just the h1 tags in my plugin pages...

            – icolumbro
            Nov 24 '18 at 15:06











          • As noted in the docs, you can pass a $hook argument and then see on what page you want your script to load :)

            – dingo_d
            Nov 25 '18 at 10:01

















          Thank you for reply but I know I must use admin_enqueue_scripts hook and wp_enqueue_style function but the problem is that doing this my CSS style affects whole admin side not my plugin settings pages only. E.g.: if in my CSS I write h1 { color: red; } every h1 tag shows in red and not just the h1 tags in my plugin pages...

          – icolumbro
          Nov 24 '18 at 15:06





          Thank you for reply but I know I must use admin_enqueue_scripts hook and wp_enqueue_style function but the problem is that doing this my CSS style affects whole admin side not my plugin settings pages only. E.g.: if in my CSS I write h1 { color: red; } every h1 tag shows in red and not just the h1 tags in my plugin pages...

          – icolumbro
          Nov 24 '18 at 15:06













          As noted in the docs, you can pass a $hook argument and then see on what page you want your script to load :)

          – dingo_d
          Nov 25 '18 at 10:01





          As noted in the docs, you can pass a $hook argument and then see on what page you want your script to load :)

          – dingo_d
          Nov 25 '18 at 10:01




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458820%2fuse-my-custom-css-just-for-my-wordpress-plugin-settings-page-how%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings