Halloween Sale 15% off Ends in See the plans
PHP

Tutorial Video Dashboard Widget

Embeds a how-to video on the dashboard, such as a walkthrough recorded for your client, with an optional short message.

Don’t have WPIDE yet? Install it on your site

Code

$wpide_tutorial = array(
    'title'   => 'How to Edit Your Website',
    'video'   => 'https://www.youtube.com/watch?v=XXXXXXXXXXX', // YouTube, Vimeo or any oEmbed URL.
    'message' => 'Watch this short walkthrough before your first edit.',
);

add_action( 'wp_dashboard_setup', function () use ( $wpide_tutorial ) {
    wp_add_dashboard_widget( 'wpide_tutorial_video', esc_html( $wpide_tutorial['title'] ), function () use ( $wpide_tutorial ) {
        if ( $wpide_tutorial['message'] ) {
            echo '<p>' . esc_html( $wpide_tutorial['message'] ) . '</p>';
        }

        $embed = wp_oembed_get( $wpide_tutorial['video'], array( 'width' => 600 ) );

        echo $embed ? '<div class="wpide-video" style="aspect-ratio:16/9">' . str_replace( '<iframe ', '<iframe style="width:100%;height:100%" ', $embed ) . '</div>' : '<p><a href="' . esc_url( $wpide_tutorial['video'] ) . '" target="_blank" rel="noopener">Open the video</a></p>';
    } );
}, 1 );

Notes

The oEmbed result is fetched from the video site; WordPress does not cache it outside posts, so keep the widget for clients only if needed.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.