Site logo

Archived topic

how to encode the email address

1 reply · Started by Sima on April 30, 2021

Viewing posts 1–2 of 2

I have created email-address-encoder snippet and added the following code:

add_shortcode( 'email', function( $attr ) {
extract( shortcode_atts( array(
'address' => '',
), $attr ) );

$email = '';
$email .= antispambot( $attr['address'] );
$email .= '
';

return $email;
} );

Then I have added a shortcode in my page with the following line:

[email address="me@me.com"]

Is this the correct way to do it? and how can I style the shortcode? I do not have any control over the shortcode. I would like to center the email address. Please help. thanks

Hi there,

theres an alternative example shortcode function provided here:

https://developer.wordpress.org/reference/functions/antispambot/#user-contributed-notes

Within the code you will see the return:

return '<a href="' . esc_url('mailto:' . antispambot( $content ) ) . '">' . esc_html( antispambot( $content ) ) . '</a>';

You could add a CSS class to the HTML it returns to which you can apply your styles eg.

return '<a class="email" href="' . esc_url('mailto:' . antispambot( $content ) ) . '">' . esc_html( antispambot( $content ) ) . '</a>';

then you can style it like so:

a.email {
    /* Your styles here */
}
This archived topic is closed to new replies.