Shortcodes Generator

Overview

Use this tool to create custom code for Shortcodes with add_shortcode() function.

Usage

  • Fill in the user-friendly form.
  • Click the “Update Code” button.
  • Copy the code to your project.
  • Or save it as a snippet and share with the community.
Shortcode tag in the content.
e.g. [tag]
The function used in the code.
Self-closing shortcode: [tag]
Enclosing shortcode: [tag]content[/tag]
Enable attributes such as
[tag foo="123" bar="456"].
Use "shortcode_atts_{$shortcode}" filter, to allow shortcode attributes filtering.
Set custom filter name.
Attribute name. Lowercase.
Default value.
e.g. [tag attr_name="default_value"]
Attribute name. Lowercase.
Default value.
Attribute name. Lowercase.
Default value.
Custom code to generate the output.
Should only "return" the text, never produce the output directly.
  Save Snippet
// Add Shortcode
function shortcode_handler( $atts , $content = null ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'header' => 'no',
			'footer' => 'no',
			'type' => 'default',
		),
	);

		//make sure the panel type is a valid styled type if not revert to default
		$panel_types = array('primary','success','info','warning','danger','default');
		$type = in_array($type, $panel_types)? $type: 'default';
	
		//start panel markup
		$output = '<div class="panel panel-'.$type.'">';
	
		//check if pannel has a header
		if ('no' != $header)
			$output .= '<div class="panel-heading">'.$header.'</div>';
	
		//add panel body content and allow shortcode in it
		$output .= '<div class="panel-body">'.trim(do_shortcode( $content )).'</div>';
	
		//check if pannel has a footer
		if ('no' != $footer)
			$output .= '<div class="panel-footer">'.$footer.'</div>';
	
		//add closing div tag
		$output .= '</div>';
	
		//return shortcode output
		return $output;

}
add_shortcode( 'bs3_panel', 'shortcode_handler' );