Output links in php

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.

Read More
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

Related posts

Leave a Reply

2 comments

  1. 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>';
    
  2. 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.