使用参数创建自闭合短代码
使用参数创建自闭合短代码
<?php
function button_shortcode( $type ) {
    extract( shortcode_atts( 
        array( 
            'type' => 'value'
         ), $type ) ); 
    // check what type user entered
    switch ($type) {
        case 'twitter':
            return '<a href="http://twitter.com/rupomkhondaker" class="twitter-button">Follw me on Twitter!</a>';
            break;
        case 'rss':
            return '<a href="http://example.com/rss" class="rss-button">Subscribe to the feed!</a>'
            break;
    }
}
add_shortcode( 'button', 'button_shortcode' );
?>
现在,你可以通过在短代码中定义类型来选择要显示的按钮。
[button type="twitter"]
[button type="rss"]