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' );