Open up your theme’s functions.php file and paste the following code somewhere between PHP tags:
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;
}
Now, when you want to get the value of the custom field, you simply use the function in your theme files like so:
<?php get_custom_field('image', TRUE); ?>
Using the “TRUE” value makes sure that the function actually echos the value, rather than just returning it.
