Last active
August 29, 2015 14:07
-
-
Save timstl/859637f7b8c78cf2f6ca to your computer and use it in GitHub Desktop.
ACF conditional the_field/get_field shortcut function
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 | |
if (function_exists('get_field') && !function_exists('tfield')) | |
{ | |
/* | |
Example usage: | |
<?php tfield('header_text', '<div class="entry">', '</div>'); ?> | |
*/ | |
function tfield($field, $before='', $after='', $echo=true) | |
{ | |
/* don't output if field doesn't have value. */ | |
if (get_field($field)) | |
{ | |
if (!$echo) | |
{ | |
$output = $before . get_field($field) . $after; | |
return $output; | |
} | |
echo $before; | |
the_field($field); | |
echo $after; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment