Last active
April 9, 2019 14:24
-
-
Save corypratt/b46e5d2c94bc74cb88ea084bd7770dac to your computer and use it in GitHub Desktop.
Shortcode using ACF to store global calls to action
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 | |
/* | |
* 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