If custom field exists


/ Published in: PHP
Save to your folder(s)

This snippet check for custom field value (customfieldname), if there is nothing it will display default value (alternative text).
This is my first WordPress Snippet :)


Copy this code and paste it in your HTML
  1. <?php $somevar = get_post_meta($post->ID, 'customfieldname', true);
  2.  
  3. if($somevar) {
  4.  
  5. echo $somevar;
  6. } else {
  7. echo 'alternative text';
  8. }?>

URL: www.h3ostudio.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.