Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted
<?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 />";
?>
share|improve this answer
    
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
1  
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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