7 days of unlimited WordPress themes, plugins & graphics - for free!* Unlimited asset downloads! Start 7-Day Free Trial
FREELessons: 15Length: 1.2 hours

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

2.2 Reinventing the Dashboard Screen

The dashboard screen is the first page you land on after having logged in. Its purpose is to give you a summary of what’s going on with your site and also provide quick access to various sections.

So, let’s see how you can customize it.

Related Links

2.2 Reinventing the Dashboard Screen

The dashboard screen is the page you'll land on after login. And its purpose is to give you a summary of what's going on with your website and also provide quick access to different sections. For example, you can open the customizer or save a quick draft. So, let's see how you can customize this. First things first, how do you remove a dashboard widget from the existing ones? Well, one way would be to uncheck it from here. But, what if you want to remove them completely? Let's say we wanna remove this quick draft widget. Well for that, we can use a function called remove meta box. So first, actually we need to hook up our own function to the wp_dashboard_setup, so we're gonna say function customize_dashboard. And we're gonna tie it in to wp_dashboard_setup. Okay, inside, we're gonna use the remove_meta_box function, which can be found in the codex. And we can actually find a list of all the dashboard widgets, so we can use this for Quick Press, that's how it's called. We simply do this, remove_meta_box. Dashboard_quick_press dashboard and side. Now let's take a look at these parameters so you can understand it better. First of all, you give it an ID, so the ID or the slug of the meta box, then the page you're removing it from, and then the context. And the context basically means the position where it's at. And it's normal, advanced, or side. And in our case, that widget is to the side here. If we take a look at the let's say comments widget here, we're gonna see it has a different position. So recent comments, it has normal. All right, so with that, let's refresh, and now that widget is gone. And it's also gone from here, from the top, good. Now, what if you wanna remove this welcome panel entirely? Well, to do that, you would simply do remove_action and you would say, welcome_panel wp_welcome_panel. And that will get rid of it entirely, including from the screen options here. Now, what if you want to add your own dashboard widget? Well, that is very simple as well. You need to use the function wp_add_dashboard_widget, so we're going to say wp_add_dashboard_widget. And this one gets three parameters, it gets an ID, so in our case let's put a simple widget that displays the current date. So we're going to say date_dashboard_widget, we're going to say ID here, then the title of the widget. Let's say today and then a callback function which is used to display the content of the widget. So we're gonna say date_dashboard_widget_function. Now, so this is the callback. Now we need to write the function that will actually display the contents. So we're going to say function, date_dashboard_widget_function. And inside, I'm simply going to echo a simple Hi, today is and we'll use the date PHP function. All right, so now let's refresh and we're going to see our new plugin here. It says today Hi, Today is the day, followed by the month and the year. And of course, we can collapse this, expand it again, move it around, if you want it to be placed right at the top or maybe you want it on the right. You can also uncheck it from here. And that's it for the dashboard. The ability to create custom widgets for it is really important because it allows you to create a really great experience for the user tailored to his needs. Now coming up next, we'll have a look at content tables and we'll find out how we can change them.

Back to the top