Last active
December 20, 2015 20:59
-
-
Save ramseyp/6194398 to your computer and use it in GitHub Desktop.
Returns first value of WordPress custom field. Runs it though wpautop() if desired. Has option for you to insert text / html before and after the value, allowing you to wrap the value with content.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Displays the content of a custom field, along with wrapping code or content. | |
* @param string $key name, or key, of the custom field. | |
* @param string $before what should be shown directly before the custom field value. | |
* @param string $after what is output directly after the custom field value. | |
* @param boolean $wpautop filters the value through wpautop(). | |
* @return string first value of the custom field, prepended by $before, followed by $after. | |
*/ | |
function s25_do_post_meta( $key, $before, $after, $wpautop ) { | |
global $post; | |
if ( $wpautop ) : | |
$custom_field = wpautop( get_post_meta($post->ID, $key, true), false ); | |
else : | |
$custom_field = get_post_meta($post->ID, $key, true); | |
endif; | |
if($custom_field) : //if the user set a custom field | |
echo $before . $custom_field . $after; | |
else : //else, return | |
return; | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment