Skip to content

Instantly share code, notes, and snippets.

@tdrayson
Created October 27, 2020 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdrayson/8a480cd4b1e90f1c9e4cc880687e46de to your computer and use it in GitHub Desktop.
Save tdrayson/8a480cd4b1e90f1c9e4cc880687e46de to your computer and use it in GitHub Desktop.
function my_acf_shortcode( $atts ){
$atts = shortcode_atts( array(
'field' => '',
'image' => ''
), $atts, 'showfield' );
if ( get_field( $atts['field'] ) && ( $atts['image'] !== '' ) ) :
return '<a href="' . get_field( $atts['field'] ) . '"><img src="' . $atts['image'] . '"></a>';
endif;
}
add_shortcode('showfield', 'my_acf_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment