Created
January 22, 2015 13:45
-
-
Save maxxscho/c53987bc2972388e241e to your computer and use it in GitHub Desktop.
Echo a field of Advanced Custom Fields, if it is present. You may prepend and append it with custom strings (HTML ;) )
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 | |
/** | |
* Echo an ACF Field if it is present | |
* @param bool|int $field Name of the field | |
* @param string $before prepend the field with this string. HTML for example | |
* @param string $after append the field with this string. HTML for example | |
* @param bool|int $post_id | |
* | |
* @return bool|void | |
* @author Markus Schober | |
*/ | |
function the_field_if($field = false, $before = '', $after = '', $post_id = false) | |
{ | |
if ( get_field($field, $post_id) ) { | |
echo $before . get_field($field, $post_id) . $after; | |
} | |
else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment