Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jentanbernardus/4471389 to your computer and use it in GitHub Desktop.
Save jentanbernardus/4471389 to your computer and use it in GitHub Desktop.
Hide or Replace the WordPress Welcome Panel [ functions.php ]
//Disable the dashboard welcome screen
//This will only hide the panel, not replace it with any other content.
add_filter("get_user_metadata", "my_own_welcome_panel", 1, 4);
function my_own_welcome_panel($null, $object_id, $meta_key, $single) {
if($meta_key === 'my_own_welcome_panel') { return 0; }
}
// You can replace the WP welcome panel with your own content using this snippet.
add_filter("get_user_metadata", "my_own_welcome_panel", 1, 4);
function my_own_welcome_panel($null, $object_id, $meta_key, $single) {
// Only work with the show_welcome_panel
if($meta_key !== 'show_welcome_panel') { return null; }
// If the user has already said they don't want to see the panel, don't show it!
$show_panel = get_user_meta( get_current_user_id(), 'my_own_welcome_panel', true );
if(empty($show_panel)) { return 0; }
// Echo your HTML or content here, but make sure to have a link like the following:
?>
<a class="welcome-panel-close" href="<?php echo esc_url( admin_url( '?my_own_welcome=0' ) ); ?>"><?php _e('Dismiss this Message'); ?></a>
<?php
// Return 0 or else the original welcome panel will show as well.
return 0;
}
// Add the functionality to update the user's settings with whether or not they have closed the panel
add_action('admin_init', 'my_own_welcome_set_welcome_panel');
function my_own_welcome_set_welcome_panel() {
if ( isset( $_GET['my_own_welcome'] ) ) {
update_user_meta( get_current_user_id(), 'my_own_welcome_panel', intval($_GET['my_own_welcome']));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment