Skip to content

Instantly share code, notes, and snippets.

@corypratt
Last active April 9, 2019 14:24
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 corypratt/b46e5d2c94bc74cb88ea084bd7770dac to your computer and use it in GitHub Desktop.
Save corypratt/b46e5d2c94bc74cb88ea084bd7770dac to your computer and use it in GitHub Desktop.
Shortcode using ACF to store global calls to action
<?php
/*
* This goes in your functions file and will create a shortcode that returns a CTA created with Advanced Custom Fields
*
*/
function lm_global_cta($atts, $content) {
$params = shortcode_atts( array(
'id' => ''
), $atts );
if ( have_rows( 'cta', 'option' ) ) :
$cta = '';
// loop through the rows of data
while ( have_rows( 'cta', 'option' ) ) : the_row();
if ( get_sub_field('unique_id') == $params['id'] ) :
// This is where you output your unique fields.
endif;
endwhile;
endif;
return $cta;
}
add_shortcode( 'globalcta', 'lm_global_cta' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment