Skip to content

Instantly share code, notes, and snippets.

@timstl
Last active August 29, 2015 14:07
Show Gist options
  • Save timstl/859637f7b8c78cf2f6ca to your computer and use it in GitHub Desktop.
Save timstl/859637f7b8c78cf2f6ca to your computer and use it in GitHub Desktop.
ACF conditional the_field/get_field shortcut function
<?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