Updated: now with more in-depth code!
So you want to modify the WordPress Dashboard Welcome Screen
There was a thread on the WPMU website that discusses how to disable the WordPress welcome screen, but the code provided didn’t work, so I figured I’d show how to do it!
The wp_welcome_panel()
function uses the show_welcome_panel
user meta setting to determine whether or not to show the welcome panel. In order to modify this setting, we’re going to add a filter to the get_user_metadata
filter, which uses the get_metadata
function.
The following code snippets should be added to your theme’s functions.php
file.
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; } }
or Show Your Own Panel
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'])); } }
The post How to Hide or Replace the WordPress Welcome Panel appeared first on KWS Blog.