Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Garconis/6801a93dfe52e345a9d794acc4607132 to your computer and use it in GitHub Desktop.
Save Garconis/6801a93dfe52e345a9d794acc4607132 to your computer and use it in GitHub Desktop.
WordPress | ACF - Shortcode to differentiate between true and false value and if value exists at all
<?php
function fs_sc_author_byline( $atts ){
// begin output buffering
ob_start();
global $post; // if outside the loop
$byline = get_field('show_author');
if ( isset($byline) && $byline == '1') {
echo 'Set and true';
}
elseif ( isset($byline) && $byline == '0') {
echo 'Set and false';
}
else {
echo 'Must not be set';
}
// end output buffering, grab the buffer contents, and empty the buffer
return ob_get_clean();
}
add_shortcode( 'fs_author_byline', 'fs_sc_author_byline' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment