0

ショートコードの属性以外はハンドラー関数に渡されていません。

Wordpress 投稿のショートコード

[k_recipe recipe="snack"]Here is some content[/k_recipe]

ショートコード機能

add_shortcode("k_recipe", "recipe_shortcode");

function recipe_shortcode($attributes, $content){

    return "Hi " . $attributes["recipe"] . " Hi " . $content;
}

ショートコード出力

Hi  Hi Here is some content

スナック値が渡されないのはなぜですか?? どんな手掛かり??

4

2 に答える 2

2

属性付きのショートコードを使用する方法は次のとおりです

function bartag_func( $atts ) {
    extract( shortcode_atts( array(
        'foo' => 'something',
        'bar' => 'something else',
    ), $atts ) );

    return "foo = {$foo}";
}
add_shortcode( 'myshortcode', 'bartag_func' );

[myshortcode foo="bar" bar="bing"]

あなたは抽出物がありません

于 2013-09-13T04:54:44.177 に答える
1

ドキュメントにあるように、抽出機能を使用する必要があるかもしれません。

// [bartag foo="foo-value"]
function bartag_func( $atts ) {
    extract( shortcode_atts( array(
        'foo' => 'something',
        'bar' => 'something else',
    ), $atts ) );

    return "foo = {$foo}";
}
add_shortcode( 'bartag', 'bartag_func' );

http://codex.wordpress.org/Shortcode_API

于 2013-09-13T04:54:47.193 に答える