Shortcode generator
The add_shortcode skeleton, with or without attributes.
Genuinely free. No sign-up, no email, no limits, no cookies. We don't store the URL you analyse.
Code
<?php
add_shortcode( 'my_button', function ( $atts ) {
$a = shortcode_atts( array(
'text' => 'Click',
'url' => '#',
), $atts, 'my_button' );
return sprintf(
'<a class="btn" href="%s">%s</a>',
esc_url( $a['url'] ),
esc_html( $a['text'] )
);
} );
// Usage: [my_button text="Buy" url="/shop"]What it's for
A shortcode turns [a-word] into dynamic content. The structure is always the same: here you get it right, with attribute handling and a return instead of echo, which is the most common mistake.
Frequently asked questions
›Why return and not echo?
Because a shortcode must return its output, not print it: with echo the content ends up at the top of the page instead of where you placed the shortcode. This boilerplate uses return correctly.