0

What I'm trying to do is quite simple: I want to add a custom field named 'Button' to each post that will show a button (image) on the page with the value as its link.

It's basically a button that will show on every post, the link that the button points to will be entered in the value field of the custom field.

This is the code I used in single.php:

<div class="button">
  <a href="<?php get_post_meta($post->ID, 'Button', true); ?>">
    <img src="<?php echo get_template_directory_uri() . '/images/button.png'; ?>" alt="link" />
  </a>
</div> 

The problem is that the output of the value field doesn't appear. The link that supposed to be on the button image is not in place. Instead the button links to the post.

This is the website in question: http://digitalmediaboard.com

1

You need to echo get_post_meta(), like this:

<div class="button">
 <a href="<?php echo get_post_meta($post->ID, 'Button', true); ?>">
   <img src="<?php echo get_template_directory_uri() . '/images/button.png'; ?>" alt="link" />
 </a>
</div> 

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.