Get WordPress Custom Field if it exists

If you want to get a custom field anywhere in your posts/pages accompanied by a phrase indicating that the output is something specific (e.g. you have a showcase and you want to include the showcased site’s url under the image but you want it styled specifically) then all you have to do is insert the following in your theme file in the position you want it to appear. If you haven’t used any custom field for your post with the specific key value (e.g. Site-Url) then this code will not output anything.

<?php if(get_post_meta($post->ID, 'Site-Url', true)): ?>
Site Url: <?php echo get_post_meta($post->ID, 'Site-Url', true); ?>
<?php endif; ?>

CATEGORY: Tips & Tricks
DATE: July 11th, 2010 & LEAVE YOUR COMMENT HERE

FILTER BY

Colors