How to register shortcode in wordpress

Single shortcode

function single_shortcode( $atts, $content = null  ) {

	return '<div class="singe_shortcode_wrapper">'.do_shortcode($content).'</div>';

}	
add_shortcode('single_shortcode', 'single_shortcode');

Shortcode with attributes

function shortcode_with_attributes( $atts, $content = null  ) {

	extract( shortcode_atts( array(
		'attribute' => '',
		'another' => ''
	), $atts ) );

	return '
        <div class="shortcode_wrapper">
            <h2>'.$attribute.'</h2>
            '.$another.'
        </div>
    ';
}	
add_shortcode('shortcode_name', 'shortcode_with_attributes');
The following two tabs change content below.

Leave a Reply

Your email address will not be published. Required fields are marked *