Did we tell you about the release of yet another generator? This cool tool will help you to add widgets to your WordPress dashboard.
What is a Dashboard Widget?
The dashboard is the first thing you see once you log in to your site admin, basically it’s the main admin screen. The dashboard has a few elements called dashboard widgets.
The widgets on the dashboard are very handy for displaying information. You can use those widgets to present general site information like stats, notes and messages (for your clients) and summarized information from other components in your site. You can also use them to show information from external sources like cloud analytics platforms, RSS feeds, data from external APIs, and whatever you might come up with, the possibilities they are really endless here.
Dashboard Widgets Generator
Our Dashboard Widgets Generator allows you to create custom code for your dashboard widgets using the wp_add_dashboard_widget() function. Simply fill in the user friendly form and get valid code using WordPress Dashboard Widgets API.
Hello World Dashboard Widget
To show you how easy it is to build your first dashboard widgets, we will start with a simple “Hello World” widget. See how simple is the syntax:
View snippet Clone snippet Download snippet
The __construct
is registering a new widget, using the add_dashboard_widget()
function, and render the widget code using render_dashboard_widget()
function.
The result in you dashboard will like this:
Let’s build a simple plugin
This plugin will add a widget to the dashboard and show the main site info. We will use the get_bloginfo()
function to retrieve the site information.
First, let’s create a readme file for our plugin:
View snippet Clone snippet Download snippet
Now, to retrieve the site information, we will use this little snippet I wrote:
View snippet Clone snippet Download snippet
Basicly we retrieve site information using the get_bloginfo()
function. Infomation like the site name, tagline, site URL ect. You can use the comments area below to sudgest extra feilds to expand the plugin.
Finaly, we will wrap this code in a wordpress dashboard widget.
View snippet Clone snippet Download snippet
This will add a widget to the WordPress dashboard summarizing our site data as follow:
The plugin is available at the WordPress Plugin Repository.
This was a very simple example, we can replace the code with any other result – Recent posts/comments, YouTube video, Twitter widget, RSS feed, site stats, information from external API or any other information.
Next time we will show you how to create more advanced widgets with options (configuration) forms. Meanwhile, we will love to hear what you think about our new generator.