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.

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 />";
?>
  • 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. – Sledge81 Aug 4 '11 at 16:27
  • 2
    yes image can be used but use single quotes ' around the something.com or escape your double quotes like so: \" – Brady Aug 4 '11 at 16:29

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.