Skip to content

Instantly share code, notes, and snippets.

@hsleonis
Created March 30, 2016 04:53
Show Gist options
  • Select an option

  • Save hsleonis/67d2a759be9e017ff0d457f69cd03b52 to your computer and use it in GitHub Desktop.

Select an option

Save hsleonis/67d2a759be9e017ff0d457f69cd03b52 to your computer and use it in GitHub Desktop.
WP add a widget to the dashboard
<?php
/**
* Add a widget to the dashboard.
*
* This function is hooked into the 'wp_dashboard_setup' action below.
* Reference: https://codex.wordpress.org/Dashboard_Widgets_API
*/
function example_add_dashboard_widgets() {
wp_add_dashboard_widget(
'example_dashboard_widget', // Widget slug.
'Example Dashboard Widget', // Title.
'example_dashboard_widget_function' // Display function.
);
}
add_action( 'wp_dashboard_setup', 'example_add_dashboard_widgets' );
/**
* Create the function to output the contents of our Dashboard Widget.
*/
function example_dashboard_widget_function() {
// Display whatever it is you want to show.
echo "Hello World, I'm a great Dashboard Widget";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment