How to disable a dashboard widget by default

Updated 1 year ago

Sometimes, in stores with a very big number of products the dashboard could be crashed because any widget is failing to load.

To fix this issue you can disable the widget which is causing the problem following the next steps:

This is only for technically experienced users.
  • Navigate to your server WordPress installation and go to wp-content > themes > your-child-theme

    If you need to learn about child themes you can visit the WordPress Codex.

  • Search the functions.php file.

  • Open the file with your text editor program.

We recommend doing a file backup before any editing.
  • Add the following code.
if ( defined( 'ATUM_PREFIX' ) && ! function_exists( 'atum_custom_change_default_widgets_layout' ) ) {
    
    /**
     * Remove the stock control widget from the Dashboard
     *
     * @param array $widgets
     *
     * @return array
     */
    function atum_custom_change_default_widgets_layout( $widgets ) {
        
        return array(
            ATUM_PREFIX . 'statistics_widget'          => array(
                'x'          => 0,                              // X edge position.
                'y'          => 0,                              // Y edge position.
                'width'      => 12,                             // Width in columns (based in 12 columns).
                'height'     => 4,                              // Height in rows.
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'sales_widget'               => array(
                'x'          => 0,
                'y'          => 5,
                'width'      => 3,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'lost_sales_widget'          => array(
                'x'          => 3,
                'y'          => 5,
                'width'      => 3,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'orders_widget'              => array(
                'x'          => 6,
                'y'          => 5,
                'width'      => 3,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'promo_sales_widget'         => array(
                'x'          => 9,
                'y'          => 5,
                'width'      => 3,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'stock_control_widget'       => array(
                'x'          => 0,
                'y'          => 10,
                'width'      => 6,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'news_widget'                => array(
                'x'          => 6,
                'y'          => 10,
                'width'      => 6,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'videos_widget'              => array(
                'x'          => 0,
                'y'          => 15,
                'width'      => 12,
                'height'     => 5,
                'min-height' => 7,
            ),
            ATUM_PREFIX . 'current_stock_value_widget' => array(
                'x'          => 0,
                'y'          => 20,
                'width'      => 6,
                'height'     => 4,
                'min-height' => 5,
                'default'    => FALSE,
            ),
        );
        
    }
    
    add_filter( 'atum/dashboard/default_widgets_layout', 'atum_custom_change_default_widgets_layout' );
}
  • You can see the default Dashboard Widgets settings in the returned array within the previous code:
    • statistics_widget
    • sales_widget
    • lost_sales_widget
    • orders_widget
    • promo_sales_widget
    • stock_control_widget
    • news_widget
    • videos_widget
    • current_stock_value_widget
  • To disable a widget by default you have to delete the Widget settings in this array. For example, if you want to disable the Current Stock Value Widget you have to delete these code lines:
ATUM_PREFIX . 'current_stock_value_widget' => array(
      'x'          => 0,
      'y'          => 20,
      'width'      => 6,
      'height'     => 4,
      'min-height' => 5,
      'default'    => FALSE,
),
  • So the function will be:
if ( defined( 'ATUM_PREFIX' ) && ! function_exists( 'atum_custom_change_default_widgets_layout' ) ) {
    
    /**
     * Remove the stock control widget from the Dashboard
     *
     * @param array $widgets
     *
     * @return array
     */
    function atum_custom_change_default_widgets_layout( $widgets ) {
        
        return array(
            ATUM_PREFIX . 'statistics_widget'          => array(
                'x'          => 0,                              // X edge position.
                'y'          => 0,                              // Y edge position.
                'width'      => 12,                             // Width in columns (based in 12 columns).
                'height'     => 4,                              // Height in rows.
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'sales_widget'               => array(
                'x'          => 0,
                'y'          => 5,
                'width'      => 3,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'lost_sales_widget'          => array(
                'x'          => 3,
                'y'          => 5,
                'width'      => 3,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'orders_widget'              => array(
                'x'          => 6,
                'y'          => 5,
                'width'      => 3,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'promo_sales_widget'         => array(
                'x'          => 9,
                'y'          => 5,
                'width'      => 3,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'stock_control_widget'       => array(
                'x'          => 0,
                'y'          => 10,
                'width'      => 6,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'news_widget'                => array(
                'x'          => 6,
                'y'          => 10,
                'width'      => 6,
                'height'     => 4,
                'min-height' => 5,
            ),
            ATUM_PREFIX . 'videos_widget'              => array(
                'x'          => 0,
                'y'          => 15,
                'width'      => 12,
                'height'     => 5,
                'min-height' => 7,
            ),
        );
        
    }
    
    add_filter( 'atum/dashboard/default_widgets_layout', 'atum_custom_change_default_widgets_layout' );
}

After you added this code, you'll need to execute the next SQL code in your database to reset the Dashboard widgets database configuration:

DELETE FROM wp_usermeta WHERE meta_key = 'atum_dashboard_widgets_layout';
We recommend doing a database backup before any editing.

It's mandatory to run this code after the functions.php editing.

Please note that if you changed your default database prefix by a custom prefix, you must change wp_ by yourcustomprefix__. For example:

DELETE FROM yourcustomprefix_usermeta WHERE meta_key = 'ATUM_DASHBOARD_WIDGETS_LAYOUT';

If you don't know how to execute SQL scripts in your database (usually people use phpMyAdmin) you'll need to contact your hosting provider and ask them the way to do that.
Did this answer your question?