Use the below example code in your theme’s functions.php file to grab all custom fields globally:
1 2 3 4 5 6 7 | function get_custom_field($key, $echo = FALSE) { global $post; $custom_field = get_post_meta( $post->ID, $key, true ); if ( $echo == false ) return $custom_field; echo $custom_field; } |
Then call the field with a single line:
1 | <?php get_custom_field('custom-field-name', TRUE); ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.