Skip to content
wp-skills
Register
tools/shortcode-generator

WordPress Shortcode Generator

WordPress Shortcode Generator is a tool that allows WordPress users to create custom shortcodes, turning complex operations into simple ones.

What goes between the square brackets. Letters, digits and underscores — anything else is rewritten, because the tag also becomes part of the callback's name.

Enclosing takes a $content argument and a closing tag; self closing does not.

Adds a shortcode_atts() call, which is what fills in the defaults for attributes the user left off.

Attributes1
  • #1

    WordPress lower-cases attribute names before your callback sees them, so this one is lower-cased too.

    Used when the shortcode is written without this attribute.

snippet.php
// Shortcode: [my_shortcode_button color="blue"]

function wp_skills_my_shortcode_button_shortcode( $atts ) {
	$atts = shortcode_atts(
		array(
			'color' => 'blue',
		),
		$atts,
		'my_shortcode_button'
	);

	$color = $atts['color'];

	// Your code...

	// A shortcode has to RETURN its output. Anything echoed here is printed
	// where WordPress happens to be rendering at the time — usually above the
	// content — rather than in place of the shortcode.
	return '';
}
add_shortcode( 'my_shortcode_button', 'wp_skills_my_shortcode_button_shortcode' );