Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a button shortcode to be used in the page/post editor (goes in functions.php)
//* Add shortcode for buttons
function nabm_button_shortcode( $atts, $content = 'Click Here' ) {
extract(shortcode_atts(array(
'url' => '#'
'target' => '',
), $atts));
$target = ($target == 'blank') ? ' target="_blank"' : '';
$button = '<a target=" 'esc_attr( $target ). '" class="button" href="' . esc_url( $url ) . '">' . esc_attr( $content ) . '</a>';
return $button;
}
add_shortcode( 'button', 'nabm_button_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment