1

I have added a menu page to my plugin. In the wp codex is described that I can use a seperate .php file for the content of the menu.

function register_custom_menu_page() {
   add_menu_page('custom menu title', 'custom menu', 'add_users', 'myplugin/myplugin-index.php', '',   plugins_url('myplugin/images/icon.png'), 6);
}

myplugin-index.php

<?php
   echo "Admin Page Test";
?>

Now I want to use custom styles (.css) in the myplugin-index.php. How can this be achieved?

BR,

mybecks

2 Answers 2

0

You could use

<!doctype html>
<head>
<style type="text/css">
#toplevel_page_custom_menu_title{
display:none !important;
}
.update-nag{
height:auto !important;
}
</style>
</head>
<body>
<div class="update-nag">
<?php
   echo "Admin Page Test";
?>
</div>
</body>
</html>

You can enqueue this way

function prefix_add_my_stylesheet() {
        wp_register_style( 'prefix-style', plugins_url('style.css', __FILE__) );
        wp_enqueue_style( 'prefix-style' );
    }
add_action( 'admin_enqueue_scripts', 'prefix_add_my_stylesheet' );

Reference: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts#Example:_Load_CSS_File_on_All_Admin_Pages

1
  • Won't this load the CSS file on any single page of the WordPress admin? Commented Sep 10, 2021 at 17:13
0

You can use wp_enqueue_style.

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.