Skip to main content
Login Join
Snippet · PHP

Display Current User Email

Shared by Utsav Tilava · August 22, 2026

4 views
1 upvote
Back to Snippets

This snippet displays the email address associated with the currently logged-in WordPress account. It uses a shortcode so the information can easily be added to any page, post, or shortcode-compatible widget.

<?php
function display_current_user_email() {

    if ( ! is_user_logged_in() ) {
        return '<p>Please log in to view your email address.</p>';
    }

    $user = wp_get_current_user();

    return '<p><strong>Email:</strong> ' . esc_html( $user->user_email ) . '</p>';
}

add_shortcode( 'current_user_email', 'display_current_user_email' );
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments