Function to get custom field data


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



Copy this code and paste it in your HTML
  1. // place following function inside functions.php
  2. function get_custom_field_value($szKey, $bPrint = false) {
  3. global $post;
  4. $szValue = get_post_meta($post->ID, $szKey, true);
  5. if ( $bPrint == false ) return $szValue; else echo $szValue;
  6. }
  7.  
  8. // use following code to call function after checking that it exists
  9. <?php if ( function_exists('get_custom_field_value') ){
  10. get_custom_field_value('home heading', true);
  11. } ?>
  12.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.