edit7279 edit7279 - 6 months ago 35
PHP Question

Remove Site URL Showing Before Email Link

I feel like this is a rookie question, but for some reason I can't figure this out.

How do I remove our site URL from appearing before the email?

echo '<a href="'.$business_email.'">Email</a>';



The email address itself is inputted in WordPress admin custom field if that makes a difference.


If you are trying to get the link to send an email you should change your code to this:

echo '<a href="mailto:'.$business_email.'">Email</a>';

It may be that when you click the link it is just appending the email to your site's URL.

If you are, in fact, getting that string directly from the database, you can try removing your website using the str_replace() function:

$baseurl = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

$business_email = str_replace( $baseurl, $business_email, '' );

echo '<a href="mailto:'.$business_email.'">Email</a>';