Using WordPress ‘get_dashboard_blog()’ PHP function

The get_dashboard_blog() WordPress PHP function retrieves the “dashboard blog”, which is the blog where users without a blog edit their profile data.

Usage

get_dashboard_blog();

Parameters

  • None

More information

See WordPress Developer Resources: get_dashboard_blog()

Note: Dashboard blog functionality was removed in WordPress 3.1, replaced by the user admin. See also get_site().

Examples

Check if the user has a dashboard blog

This example checks if the current user has a dashboard blog and displays a message accordingly.

$dashboard_blog = get_dashboard_blog();

if ( ! $dashboard_blog ) {
    echo "You don't have a dashboard blog.";
} else {
    echo "Your dashboard blog is: " . $dashboard_blog->blogname;
}

Display a list of users and their dashboard blogs

This example retrieves a list of users and displays their dashboard blogs.

$users = get_users();

foreach ( $users as $user ) {
    $dashboard_blog = get_dashboard_blog( $user->ID );

    if ( ! $dashboard_blog ) {
        echo $user->display_name . " does not have a dashboard blog.";
    } else {
        echo $user->display_name . "'s dashboard blog is: " . $dashboard_blog->blogname;
    }
}

This example displays a link to the user’s dashboard blog.

$dashboard_blog = get_dashboard_blog();

if ( $dashboard_blog ) {
    echo '<a href="' . $dashboard_blog->siteurl . '">Visit your dashboard blog</a>';
} else {
    echo "You don't have a dashboard blog.";
}

Display the user’s dashboard blog info in a table

This example displays the user’s dashboard blog information in a table format.

$dashboard_blog = get_dashboard_blog();

if ( $dashboard_blog ) {
    echo '<table>';
    echo '<tr><td>Blog Name:</td><td>' . $dashboard_blog->blogname . '</td></tr>';
    echo '<tr><td>Blog URL:</td><td>' . $dashboard_blog->siteurl . '</td></tr>';
    echo '</table>';
} else {
    echo "You don't have a dashboard blog.";
}

Show the dashboard blog info in the admin panel

This example adds a widget to the WordPress admin dashboard that displays the user’s dashboard blog information.

function show_dashboard_blog_info() {
    $dashboard_blog = get_dashboard_blog();

    if ( ! $dashboard_blog ) {
        echo "You don't have a dashboard blog.";
    } else {
        echo 'Your dashboard blog is: <strong>' . $dashboard_blog->blogname . '</strong><br>';
        echo 'Visit your dashboard blog: <a href="' . $dashboard_blog->siteurl . '">' . $dashboard_blog->siteurl . '</a>';
    }
}

function register_dashboard_blog_widget() {
    wp_add_dashboard_widget( 'dashboard_blog_info', 'Dashboard Blog Info', 'show_dashboard_blog_info' );
}

add_action( 'wp_dashboard_setup', 'register_dashboard_blog_widget' );