0

Using the following code in order to display custom field value, how can I automatically make it into a hyperlink?

<?php
  $custom_fields = get_post_custom($post_id); //Current post id
  $my_custom_field = $custom_fields['website']; //key name
  foreach ( $my_custom_field as $key => $value )
  echo $key . " => " . $value . "<br />";
?>

Presently if website value is set to http://www.abc.com then it would display http://www.abc.com instead i'd like for it to display as Click Here where it hyperlinks instead.

1 Answer 1

3
<?php
  $custom_fields = get_post_custom($post_id); //Current post id
  $my_custom_field = $custom_fields['website']; //key name
  foreach ( $my_custom_field as $key => $value )
  echo $key . " => <a href='" . $value . "'>Click Here</a><br />";
?>
2
  • Thanks a ton Brady.. small question though.. how can i include an image in place of Click here. I tried putting in <img src="something.com"> but I get php error. Commented Aug 4, 2011 at 16:27
  • 2
    yes image can be used but use single quotes ' around the something.com or escape your double quotes like so: \"
    – Scott
    Commented Aug 4, 2011 at 16:29

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.