Php 获取具有多个属性的短代码
我想创建具有多个属性的Php 获取具有多个属性的短代码,php,wordpress,plugins,shortcode,Php,Wordpress,Plugins,Shortcode,我想创建具有多个属性的shortcode。 但我只能处理单个属性,不能处理多个属性 我只能做到这一点: add_shortcode('test','get_shortcode'); 但是我想创建这样的shortcode: add_shortcode('test id=1 title=test','get_shortcode'); 我想在我的页面中这样称呼这个shortcode do_shortcode('[test id="1" title="test"]'); 您好,添加您的函数$att
shortcode
。
但我只能处理单个属性,不能处理多个属性
我只能做到这一点:
add_shortcode('test','get_shortcode');
但是我想创建这样的shortcode
:
add_shortcode('test id=1 title=test','get_shortcode');
我想在我的页面中这样称呼这个shortcode
do_shortcode('[test id="1" title="test"]');
您好,添加您的函数$atts,就像这样
function bartag_func( $atts ) {
$atts = shortcode_atts(
array(
'foo' => 'no foo',
'bar' => 'default bar',
), $atts, 'bartag' );
return 'bartag: ' . $atts['foo'] . ' ' . $atts['bar'];
}
add_shortcode( 'bartag', 'bartag_func' );
它的显示结果类似于[bartag foo=“考拉”bar=“熊”]