I'm trying to create an anchor tag and using a variable as the link.

Here's what my template looks like.

  $website = tribe_get_event_website_link();
  echo '<a href="' . $website. '">REGISTER</a>';

So I'm creating a variable that will hold the link the I want to anchor it. And when I echo it back, it appears, but it doesn't come out properly. Here's what it looks like.


Any clue on what I'm doing wrong?


I also tried

<a href="<?php echo $website ?>">REGISTER</a>

but it still produces the same thing.

closed as off-topic by Mark Kaplun, Jack Johansson, Howdy_McGee Aug 18 '17 at 3:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Looks like that tribe_... function is already echoing it. – hwl Aug 7 '17 at 17:22
  • alright cool. So if I just use 'echo $website' it works fine and displays the link address. I want to make it an anchor with the text 'REGISTER'. Any suggestions? – David Kim Aug 7 '17 at 17:52
  • are you saying that using echo $website displays, as just text, the url: http://google.com ? – hwl Aug 7 '17 at 18:52

It's not really a WordPress related question, but it's a simple one. The tribe_get_event_website_link() function you are using outputs a full link. You can use SimpleXML to extract the href part and then use it later. It's as simple as this:

$website = tribe_get_event_website_link();
$xml = new SimpleXMLElement( $website );
echo '<a href="' . $xml['href']. '">REGISTER</a>';

If you are unable to store the functions value inside a variable (for example, if the function echos it), you can use ob_get_clean():



$website = ob_get_clean();

Now proceed with extracting the href as mentioned above.

  • 1
    I think OP just has the wrong function for what he wants to do. But that (and the fact that this whole question is off topic), aside, thank you for that SimpleXML example. I think it just solved something else for me. cheers! – hwl Aug 7 '17 at 19:10

Replace tribe_get_event_website_link() with tribe_get_event_website_url().

The first one is generating the link code. The second is just returning the url, which is what you need for the href.

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