Task

How to customize the Dashboard – eliminate dashboard widgets, add your own widget, such as Tutorial links / video without a plugin.

Why you should customize your backend ?

Steps

Step 1 : Create a child theme

	
        <?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}

Step 2: Removing custom widget

	
            function wpexplorer_remove_menus() {
                remove_menu_page( 'themes.php' );         // Appearance
                remove_menu_page( 'plugins.php' );        // Plugins
                remove_menu_page( 'users.php' );          // Users
                remove_menu_page( 'tools.php' );          // Tools
                remove_menu_page( 'options-general.php' ); // Settings
            }
            add_action( 'admin_menu', 'wpexplorer_remove_menus' );
        

Step 3: Adding custom widget

	
                // Function that outputs the contents of the dashboard widget
                function dashboard_widget_function( $post, $callback_args ) {
                    echo "Hello World, this is my first Dashboard Widget!";
                }
                
                // Function used in the action hook
                function add_dashboard_widgets() {
                    wp_add_dashboard_widget('dashboard_widget', 'Example Dashboard Widget', 'dashboard_widget_function');
                }
                
                // Register the new dashboard widget with the 'wp_dashboard_setup' action
                add_action('wp_dashboard_setup', 'add_dashboard_widgets' );
                
            
            

Step 4: Advanced Adding widget

	
                    add_action( 'wp_dashboard_setup', 'prefix_add_dashboard_widget' );

function prefix_add_dashboard_widget() {
wp_add_dashboard_widget(
'my_dashboard_widget',
'Featured Dashboard Page',
'prefix_dashboard_widget',
'prefix_dashboard_widget_handle'
);
}

function prefix_dashboard_widget() {
# get saved data
if( !$widget_options = get_option( 'my_dashboard_widget_options' ) )
$widget_options = array( );

# default output
$output = sprintf(
'<h2 style="text-align:right">%s</h2>',
__( 'Please, configure the widget ☝' )
);

# check if saved data contains content
$saved_feature_post = isset( $widget_options['feature_post'] )
? $widget_options['feature_post'] : false;

# custom content saved by control callback, modify output
if( $saved_feature_post ) {
$post = get_post( $saved_feature_post );
if( $post ) {
$content = do_shortcode( html_entity_decode( $post->post_content ) );
$output = "<h2>{$post->post_title}</h2><p>{$content}</p>";
}
}
echo "<div class='feature_post_class_wrap'>
<label style='background:#ccc;'>$output</label>
</div>
";
}

function prefix_dashboard_widget_handle()
{
# get saved data
if( !$widget_options = get_option( 'my_dashboard_widget_options' ) )
$widget_options = array( );

# process update
if( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['my_dashboard_widget_options'] ) ) {
# minor validation
$widget_options['feature_post'] = absint( $_POST['my_dashboard_widget_options']['feature_post'] );
# save update
update_option( 'my_dashboard_widget_options', $widget_options );
}

# set defaults
if( !isset( $widget_options['feature_post'] ) )
$widget_options['feature_post'] = '';


echo "<p><strong>Available Pages</strong></p>
<div class='feature_post_class_wrap'>
<label>Title</label>";
wp_dropdown_pages( array(
'post_type' => 'page',
'selected' => $widget_options['feature_post'],
'name' => 'my_dashboard_widget_options[feature_post]',
'id' => 'feature_post',
'show_option_none' => '- Select -'
) );
echo "</div>";
}