EDIT 2
Multiple unnamed parameters, starting with equals sign.
function postintro_bb_shortcode( $atts ) {
// remove equals sign from first unnamed param
if ( isset( $atts[0] ) && strpos( $atts[0], '=' ) !== false ) {
$atts[0] = substr( $atts[0], 1 );
}
// Param array to string
$intro = is_array( $atts ) ? implode( ' ', $atts ) : '';
return '<div class="postintro">' . esc_html( $intro ) . '</div>';
}
add_shortcode( 'postintro_bb', 'postintro_bb_shortcode' );
[postintro_bb=Vivamus sit amet turpis ultricies lorem dignissim sollicitudin id in ex]
Unnamed parameter with closing tag
function source_shortcode( $atts, $content = null ) {
// remove equals sign from first unnamed param
if ( isset( $atts[0] ) && strpos( $atts[0], '=' ) !== false ) {
$atts[0] = substr( $atts[0], 1 );
}
return '<a href="' . esc_url( $atts[0] ) . '">' . esc_html( $content ) . '</a>';
}
add_shortcode( 'source', 'postintro_b_shortcode' );
[source=”http://www.example.com/”]test[/source]
EDIT
Here’s few ways how to define and use custom shortcodes.
Shortcode with closing tag
function postintro_shortcode( $atts , $content = null ) {
return '<div class="postintro">' . $content . '</div>';
}
add_shortcode( 'postintro', 'postintro_shortcode' );
[postintro]test[/postintro]
Self closing shortcode tag.
Apparently unnamed parameters work too.
function postintro_b_shortcode( $atts ) {
$intro = ! empty( $atts[0] ) ? $atts[0] : '';
return '<div class="postintro">' . $intro . '</div>';
}
add_shortcode( 'postintro_b', 'postintro_b_shortcode' );
[postintro_b blahblah]
Self-closing shortcode tag with named parameter.
function postintro_c_shortcode( $atts ) {
$intro = ! empty( $atts['intro'] ) ? $atts['intro'] : '';
return '<div class="postintro">' . $intro . '</div>';
}
add_shortcode( 'postintro_c', 'postintro_c_shortcode' );
[postintro_c intro=”afdfds”]
Original answer
The shortcode API is freaking out, because your shortcode name has brackets. Change
add_shortcode( '[postintro]', 'postintro_shortcode' );
to
add_shortcode( 'postintro', 'postintro_shortcode' );