Halloween Sale 15% off Ends in See the plans
PHP

Embed an External Analytics Dashboard

Adds a dashboard widget that shows a shared dashboard from another service, such as a public Plausible, Looker Studio or uptime status page, so clients see their numbers without another login.

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

Code

// Public embed or share link (https only).
$wpide_embed_url    = 'https://plausible.io/share/example.com?auth=YOUR_SHARED_LINK_KEY&embed=true&theme=light';
$wpide_embed_title  = 'Site analytics';
$wpide_embed_height = 600;

add_action( 'wp_dashboard_setup', function () use ( $wpide_embed_url, $wpide_embed_title, $wpide_embed_height ) {
    if ( ! current_user_can( 'edit_posts' ) || 0 !== strpos( $wpide_embed_url, 'https://' ) ) {
        return;
    }

    wp_add_dashboard_widget( 'wpide_external_embed', $wpide_embed_title, function () use ( $wpide_embed_url, $wpide_embed_title, $wpide_embed_height ) {
        printf(
            '<iframe src="%s" title="%s" loading="lazy" referrerpolicy="no-referrer" style="width:100%%;height:%dpx;border:0"></iframe><p><a href="%s" target="_blank" rel="noopener">Open in a new tab</a></p>',
            esc_url( $wpide_embed_url ),
            esc_attr( $wpide_embed_title ),
            (int) $wpide_embed_height,
            esc_url( $wpide_embed_url )
        );
    } );
} );

Notes

Paste the service's public share or embed link into $wpide_embed_url; the service must allow being shown in a frame.

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.