Creating Custom WordPress Admin Page

In some cases when creating wordpress site for a client or yourself, you might need to make custom admin page. For example a client will ask to do a page with simple static text, or with dynamic data from custom database tables, which can only be seen in wordpress admin panel, and might be even seen only by users who have specifig admin role. Another example is page for a plugin with instructions how to use it. Creating these kinds of admin pages is relatively easy. So let’s get started!

Registering Page in functions.php

The first step would be register custom admin page in themes functions.php file. As you might guess, when switching between themes, the same proccess of creating admin page will be needed. The code for registering page:

 As you see, add_menu_page() is the function which will do it. In the comments I explained about each parameter that can be passed to the function. Function custom_page() is to identify which file it will use. More about admin roles which can be specified as $capability variable, visit official wordpress documentation about roles and capabilities.

Setting Up Admin Page File

Now that we have registered our admin page, and specified which file it will use, create in themes root folder custom.php file, and yes, you’re done! You can use your own styles for making admin page, or you can use WordPress default styles for buttons, tables, tabs and so on. A great plugin, where you can see styles that wordpress admin is using, visit here.

Adding Custom CSS or JS

The recomended way for adding CSS or JS files in WordPress would be through enqueuing them to the hook named admin_enqueue_scripts.  So the code would look like this:

CSS

 JavaScript

That’s it. Now you can customize it as you like!

Let me know in the comments if you have any suggestions to add to this post or have any troubles.

Leave a Reply

Your email address will not be published.

*
*