2 回答
TA贡献1780条经验 获得超5个赞
使用API的简码标记的最简单示例:[footag foo =“ bar”]
function footag_func( $atts ) {
return "foo = {$atts['foo']}";
}
add_shortcode( 'footag', 'footag_func' );
具有默认属性的示例:[bartag foo =“ bar”]
function bartag_func( $atts ) {
$atts = shortcode_atts( array(
'foo' => 'no foo',
'baz' => 'default baz'
), $atts, 'bartag' );
return "foo = {$atts['foo']}";
}
add_shortcode( 'bartag', 'bartag_func' );
包含内容的示例:[baztag] content [/ baztag]
function baztag_func( $atts, $content = "" ) {
return "content = $content";
}
add_shortcode( 'baztag', 'baztag_func' );
如果您的插件设计为类,请编写以下内容:
class MyPlugin {
public static function baztag_func( $atts, $content = "" ) {
return "content = $content";
}
}
add_shortcode( 'baztag', array( 'MyPlugin', 'baztag_func' ) );
- 2 回答
- 0 关注
- 141 浏览
添加回答
举报