Skip to content

Instantly share code, notes, and snippets.

@JodiWarren
Created September 2, 2014 15:22
Show Gist options
  • Save JodiWarren/dc9e95da3797409ead8d to your computer and use it in GitHub Desktop.
Save JodiWarren/dc9e95da3797409ead8d to your computer and use it in GitHub Desktop.
Advanced Custom Fields (ACF) get_field helper function
/**
* Simple boolean helper to check if ACF is on.
* @return boolean
*/
function is_acf(){
return function_exists( 'get_field' ) ? true : false;
}
/**
* Helper function for ACF get_field function
* @param string $field Field name
* @param integer $post_id Optionally pass the post ID
* @return varies Returns contents of get_field
*/
function gf( $field, $post_id = null ) {
if ( ! is_acf() ) {
return false;
}
if ( get_field( $field, $post_id ) ) {
return get_field( $field, $post_id );
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment