0

Not sure what but the attributes from the shortcode aren't being passed to the handler function.

Shortcode in Wordpress Post

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

Shortcode Function

add_shortcode("k_recipe", "recipe_shortcode");

function recipe_shortcode($attributes, $content){

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

Shortcode Output

Hi  Hi Here is some content

Why isnt the snack value being passed?? Any clue??

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 回答