【问题标题】:Getting shortcode with multiple attributes获取具有多个属性的简码
【发布时间】:2017-03-18 05:53:33
【问题描述】:

我想创建具有多个属性的shortcode。 但我只能处理单个而不是多个属性。

我只能这样做:

add_shortcode('test','get_shortcode');

但我想像这样创建shortcode

add_shortcode('test id=1 title=test','get_shortcode');

我想在我的页面中这样称呼这个shortcode

do_shortcode('[test id="1" title="test"]');

【问题讨论】:

    标签: php wordpress plugins shortcode


    【解决方案1】:

    你好,像这样添加你的函数 $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="koala" bar="bears"]

    【讨论】:

      猜你喜欢
      • 2021-12-04
      • 2017-04-23
      • 2013-11-15
      • 2012-03-29
      • 1970-01-01
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多