Skip to content

Instantly share code, notes, and snippets.

@mikeott
Created November 24, 2022 07:51
Show Gist options
  • Save mikeott/9a10016297b4bacb4353546a8f15b63b to your computer and use it in GitHub Desktop.
Save mikeott/9a10016297b4bacb4353546a8f15b63b to your computer and use it in GitHub Desktop.
Shortcode with attributes
<?php /*
Shortcode CTA button for use in the editor.
Example usage:
[button href="https://www.google.com.au" target="_blank"]Visit Google[/button]
*/
function button( $atts, $content = null ) {
$a = shortcode_atts( array(
'class' => 'button-link external',
'href' => '#',
'target' => '_self'
), $atts );
return '<a class="' . esc_attr($a['class']) . '" href="' . esc_attr($a['href']) . '" target="' . esc_attr($a['target']) . '" >' . $content . '</a>';
}
add_shortcode( 'button', 'button' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment