How to Remove the Current Theme from the Right Now Dashboard Widget in WordPress

WPTurbo » Snippets » How to Remove the Current Theme from the Right Now Dashboard Widget in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you looking to declutter your WordPress dashboard by removing the current theme from the "Right Now" dashboard widget? Having too many details displayed can sometimes be overwhelming and counterproductive. In this article, we will guide you through the simple steps required to remove the current theme details from the "Right Now" dashboard widget area, thus creating a cleaner and more focused workspace within your WordPress site.

					function wpturbo_remove_theme_from_dashboard_widget( $items ) {
    if( isset( $items['wp-version-message'] ) ) {
        unset( $items['wp-version-message'] );
    }
    return $items;
}
add_filter( 'update_right_now_text', 'wpturbo_remove_theme_from_dashboard_widget' );
				

The purpose of the script in this code snippet is to remove the current theme from the ‘At a Glance’ or ‘Right Now’ dashboard widget. This can be very useful when you’re working on a project and you don’t want the theme in use to be displayed in the dashboard. Now, let’s break down the code and understand how it works.

The function wpturbo_remove_theme_from_dashboard_widget() is the core part of this snippet. Calculations or logic you want to perform are coded here.

function wpturbo_remove_theme_from_dashboard_widget( $items ) {
    if( isset( $items['wp-version-message'] ) ) {
        unset( $items['wp-version-message'] );
    }
    return $items;
}

This function accepts one parameter $items. The $items array contains all the data displayed in the ‘Right Now’ widget, including information on the current version of WordPress, the active theme, the number of posts, pages, etc.

Therefore, $items['wp-version-message'] specifically refers to the information on the current version of WordPress and the active theme.

With the isset() function, we check whether $items['wp-version-message'] exists. If it does, this line of code proceeds to the next line.

unset( $items['wp-version-message'] );

With the unset() function, we remove the specified element from the $items array which in this case is 'wp-version-message'.

After the unset() function is executed, it will remove the current theme and WordPress version information from the dashboard widget. Importantly, the function returns the edited $items array, ensuring that all other information remains intact on the dashboard.

In order for this functionality to occur, we need to bind our function wpturbo_remove_theme_from_dashboard_widget() to a specific WordPress action hook.

add_filter( 'update_right_now_text', 'wpturbo_remove_theme_from_dashboard_widget' );

This calls the add_filter() function which attaches the wpturbo_remove_theme_from_dashboard_widget() function to the update_right_now_text filter hook that WordPress provides. When WordPress fires this hook, it simultaneously triggers our function, implying the execution of what we have coded. This will remove the WordPress version and active theme details from the ‘Right Now’ dashboard widget.

Register an account to save your snippets or go Pro to get more features.