# Member Dashboard Shortcode

> Adds a [wpide_account] shortcode that greets the logged-in member and shows their avatar, membership details, recent posts and comments, and account links.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: account, dashboard, shortcode
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/member-account-dashboard/

## Code

```php
// Label => URL for the links box. Use full URLs or paths like /account/edit/.
$wpide_account_links = array(
    'Edit profile' => admin_url( 'profile.php' ),
);

add_shortcode( 'wpide_account', function () use ( $wpide_account_links ) {
    if ( ! is_user_logged_in() ) {
        return '<p class="wpide-account-login">Please <a href="' . esc_url( wp_login_url( get_permalink() ) ) . '">log in</a> to see your account.</p>';
    }

    $user  = wp_get_current_user();
    $roles = array_map( function ( $role ) {
        return isset( wp_roles()->role_names[ $role ] ) ? translate_user_role( wp_roles()->role_names[ $role ] ) : $role;
    }, $user->roles );

    $html  = '<div class="wpide-account">';
    $html .= '<div class="wpide-account__head" style="display:flex;gap:1em;align-items:center;flex-wrap:wrap">' . get_avatar( $user->ID, 72, '', '' );
    $html .= '<div><h2 style="margin:0">' . esc_html( sprintf( 'Hello, %s', $user->first_name ? $user->first_name : $user->display_name ) ) . '</h2>';
    $html .= '<p style="margin:0">' . esc_html( sprintf( 'Member since %s', wp_date( get_option( 'date_format' ), strtotime( $user->user_registered . ' UTC' ) ) ) ) . ( $roles ? ' &middot; ' . esc_html( implode( ', ', $roles ) ) : '' ) . '</p></div></div>';

    if ( current_user_can( 'edit_posts' ) ) {
        $posts = get_posts( array( 'author' => $user->ID, 'post_status' => array( 'publish', 'draft', 'pending' ), 'numberposts' => 5, 'no_found_rows' => true ) );

        if ( $posts ) {
            $html .= '<h3>Your recent posts</h3><ul>';
            foreach ( $posts as $post ) {
                $html .= '<li><a href="' . esc_url( 'publish' === $post->post_status ? get_permalink( $post ) : get_edit_post_link( $post ) ) . '">' . esc_html( get_the_title( $post ) ) . '</a> <small>(' . esc_html( get_post_status_object( $post->post_status )->label ) . ')</small></li>';
            }
            $html .= '</ul>';
        }
    }

    $comments = get_comments( array( 'user_id' => $user->ID, 'number' => 5, 'status' => 'approve', 'no_found_rows' => true ) );

    if ( $comments ) {
        $html .= '<h3>Your recent comments</h3><ul>';
        foreach ( $comments as $comment ) {
            $html .= '<li><a href="' . esc_url( get_comment_link( $comment ) ) . '">' . esc_html( wp_trim_words( $comment->comment_content, 12 ) ) . '</a></li>';
        }
        $html .= '</ul>';
    }

    $html .= '<h3>Your account</h3><ul class="wpide-account__links">';
    foreach ( $wpide_account_links as $label => $url ) {
        $html .= '<li><a href="' . esc_url( $url ) . '">' . esc_html( $label ) . '</a></li>';
    }
    $html .= '<li><a href="' . esc_url( wp_logout_url( home_url( '/' ) ) ) . '">Log out</a></li></ul></div>';

    return $html;
} );
```

## Notes

Set $wpide_account_links to your own pages (for example a page holding [wpide_edit_profile]); visitors who are not logged in get a login link.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Member Dashboard Shortcode" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
