I need to let my WP site go external with some links.

I've got this variable in function.php

$link=<a href=". $_COOKIE['link'] .">TEXT SHOWN</a>

Where $_COOKIE['link'] contains a certain link shown for every case I have to manage.

My code currently leads to this: http://my_wordpress.com/link.com

But, instead I need to go to: http://link.com

  • Hi, which function did you use to save the cookie data?
    – Jack Johansson
    Jan 26 '17 at 21:55
  • You're probably missing the protocol? i.e http:// in your code, or while setting the link cookie. esc_url($_COOKIE['link']) would do it either way.
    – Ismail
    Jan 26 '17 at 23:03

You forgot to add the "http" to the url

Try please this:

$link = "<a href='http://". $_COOKIE['link'] ."'>TEXT SHOWN</a>";

You also can adjust and add the http:// to the $_COOKIE itself.

If you want that the new link will open in a new tab, add target='_blank' like so:

$link = "<a href='http://". $_COOKIE['link'] ."' target='_blank'>TEXT SHOWN</a>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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