Last active
August 29, 2015 14:10
-
-
Save robgolbeck/eca68d50fa8e45cc1b8c to your computer and use it in GitHub Desktop.
WordPress Add Custom Dashboard Widgets and Hide Unnecessary Ones
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add Custom Dashboard Widgets | |
// This example adds a 'welcome' message to the dashboard. | |
' | |
add_action('wp_dashboard_setup', 'sw_custom_dashboard_widgets'); | |
function sw_custom_dashboard_widgets() { | |
global $wp_meta_boxes; | |
$normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core']; | |
$sw_widget_backup = array( 'sw_custom_dashboard_widgets' => $normal_dashboard['sw_custom_dashboard_widgets'] ); | |
unset( $normal_dashboard['sw_custom_dashboard_widgets'] ); | |
$sorted_dashboard = array_merge( $sw_widget_backup, $normal_dashboard ); | |
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; | |
// Widget heading | |
wp_add_dashboard_widget('custom_help_widget', 'Welcome to your website!', 'custom_dashboard_help'); | |
} | |
function custom_dashboard_help() { | |
// Add your custom widget content here. | |
echo '<p>Access your <a href="#" target="_blank">WordPress User Guide here</a>.</p> | |
<h4>More resources</h4> | |
<p><a href="developer.wordpress.org/reference" target="_blank">WordPress Code Reference</a></p> | |
<p><a href="http://codex.wordpress.org" target="_blank">WordPress Codex</a></p> | |
<p><a href="http://wordpress.tv" target="_blank">WordPress TV</a></p>' | |
;} | |
// Remove Unnecessary Dashboard Widgets | |
function remove_dashboard_meta() { | |
remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_primary', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); | |
remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); | |
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_activity', 'dashboard', 'normal');//since 3.8 | |
} | |
add_action( 'admin_init', 'remove_dashboard_meta' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment