Shortcode to return the User's domain from their email address

Est. Reading: 1 minute
By: jamesbayley
Created: 09/14/2018
Category:
Difficulty: Intermediate

Shortcode to return the User's domain from their email address

×Warning: This tutorial was created 2290 days ago. Some of the information may be out of date with more recent versions of Formidable. Please proceed with caution and always perform a backup before adding custom code.

Add this snippet to your functions.php file or use the Code Snippets plugin:

add_shortcode('users-email-domain',extract_domain_func);
function extract_domain_func(){
   $current_user = wp_get_current_user();
   $email = $current_user->user_email;
   if( filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
      // split on @ and return last value of array (the domain)
     $domain = array_pop(explode('@', $email));
     return $domain;
   }
}

Usage [users-email-domain]

Leave a Reply

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crosschevron-leftchevron-rightarrow-right