Skip to content

Instantly share code, notes, and snippets.

@coulterpeterson
Created May 17, 2023 18:42
Show Gist options
  • Save coulterpeterson/3c9ed108bfd019fa3ca81278bca49d00 to your computer and use it in GitHub Desktop.
Save coulterpeterson/3c9ed108bfd019fa3ca81278bca49d00 to your computer and use it in GitHub Desktop.
WordPress Shortcode for Outputting Current User's Email Address
<?php
add_shortcode('user_email', function($atts) {
$the_atts = shortcode_atts([
"encode" => 'false'
], $atts);
if( is_user_logged_in() ) {
$current_user = wp_get_current_user();
if( $the_atts['encode'] == 'true' ) {
return urlencode($current_user->user_email);
} else {
return $current_user->user_email;
}
}
return "";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment