-1

I want to link a external url as follows:

$url='www.example.com';
$output ='<div class="button"><a href="'.$url.'"> View Profile</a></div>';

I run this wordpress web app at my localhost and base url is localhost/wordpress. When I echo $output it produce a link for view profile: localhost/wordpress/www.example.com. But it should be www.facebook.com

What change shall i make?

1
  • Use http:// or https:// before your URL.
    – Saikat
    Commented Dec 15, 2017 at 16:29

2 Answers 2

2

@Sam is close, but I think you need to do this:

$url = 'http://www.example.com';

Without the protocol in front, you get the wrong result. Change to

$url = 'https://www.example.com';

if you need an SSL link.

0

You have a / thats not needed in the href this will add the link to the end of your current url hence localhost/wordpress/www.example.com

    $url='www.example.com';
    $output ='<div class="button"><a href="'.$url.'"> View Profile</a></div>';
    echo $output; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.