Reputation: 522
I've got a piece of wordpress code that outputs a string (which is a url)
I need to convert this output to a link.
echo get_post_meta($post->ID, "Link", true);
The code is already inside tags as there are other php calls in the file too.
How do I modify the code to output a link?
Thanks
Upvotes: 1
Views: 267
Reputation: 1201
Because PHP can echo literal HTML code, you can simply output the link inside a hyperlink.
echo "<a href=\"" . get_post_meta($post->ID, "Link", true) . "\">Your Link Name</a>";
Alternatively, you can choose to close and reopen the PHP tag before and after the echo statement. The above is the same as...
?>
<a href="
<?php echo get_post_meta($post->ID, "Link", true); ?>
">Your Link Name</a>
<?php
The second method is handy when you have large blocks of output and you don't want to make individual echo statements all over the place.
Upvotes: 0
Reputation: 1758
something like this?
echo '<a href="'.get_post_meta($post->ID, "Link", true).'">'.get_post_meta($post->ID, "Link", true).'</a>';
or
$link=get_post_meta($post->ID, "Link", true);
echo '<a href="'.$link.'">'.$link.'</a>';
Upvotes: 1