WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the following to display a custom field value in my posts:

<?php echo get_post_meta($post->ID, 'wikipedia', true); ?>

How do I add this value to the output, where '$tag' takes the tag of the post:

- <a href="wikipedia.org/wiki/**$tag**">Wikipedia</a>

What I've tried, unsuccessfully:

<?php echo get_post_meta($post->ID, 'wikipedia', true . '- <a href="wikipedia.org/wiki/$tag">Wikipedia</a>'); ?>

share|improve this question
up vote 1 down vote accepted
<?php $tag = get_post_meta($post->ID, 'wikipedia', true); ?>

<?php if (isset($tag) && $tag != '') : ?>
    <a href="wikipedia.org/wiki/<?php echo $tag; ?>" title="Wiki this!">Wikipedia</a>
<?php endif; ?>

To explain it a bit: First you put the data in a variable, then if the variable has some data, it will show the link and echo the data after /wiki/. You can use the variable also on other places like so: <a href="wikipedia.org/wiki/<?php echo $tag; ?>">Wikipedia (<?php echo $tag; ?>)</a>

share|improve this answer
thanks but the problem with that is that the link will appear even when I don't add content to the custom field. – AHCo Dec 19 '11 at 4:51
You don't need the isset check, it'll come back as an empty value if it's not set or if it's empty, so it's better to use if( !empty( $whatever ) ) for the conditional block. – t31os Dec 19 '11 at 17:05

Your Answer


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.