skip to Main Content

On my website I have a list of members and for each of them I display some info. One is the email address.
I would like to show the email address as an icon rather than the actual email address.
The email is dynamically populated by the

<?php
    $email_address = $user->user_email;
    if ( ! empty( $email_address ) ) {
        ?>
<div><span class="label">Email address</span><br> <?php echo esc_html( $email_address ); ?></div>
<?php
    }
    ?>

How can I add the icon here? I will remove the label as well and just show the icon.
Thanks

2

Answers


  1. Chosen as BEST ANSWER

    Sorry, one more. I tried to apply the same code to the website but doesn't work.

        $g_website = get_user_meta( $user_id, 'g_website', true );
                                if ( ! empty( $g_website ) ) {
                                    ?>
                                    <div><span class="label">Website: </span><?php echo esc_html( $g_website ); ?></div>
                                    <?php
                                }
    

    How in this case the code will be different?

    THANKS!!!


  2. A standard image tag should work. Here’s how to add with PHP (untested):

    $email_address = $user->user_email;
    
    if ( ! empty( $email_address ) && is_email( $email_address ) ) {
        $email_icon_src = ''; // Add the URL to your icon here
    
        printf( 
            '<div><a href="%s"><img src="%s" /></a></div>', 
            esc_url( 'mailto:' . $email_address ), 
            esc_url( $email_icon_src ) 
        );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search