如何在 WordPress 中创建嵌套 shortcode

wpfans 发表在 WordPress教程

当在文章或者页面添加 shortcode 时,它将被插件或者主题函数中的 shortcode 处理函数的输出所替换。首先创建一个简单的示例:

// 创建一个按钮
function ContactButton( $params, $content = null ) {
	extract( shortcode_atts( array( 'url' => '/contact-us', 'type' => 'style1' ), $params ) );
	return '<a class="button ' . $type . '" href="' . $url . '">' . ucwords( $content ) . '</a>';
}
add_shortcode( 'button', 'ContactButton' );