Php 短代码属性未传递给处理程序函数
不确定是什么,但短代码中的属性没有传递给处理程序函数 Wordpress Post中的短代码Php 短代码属性未传递给处理程序函数,php,wordpress,api,plugins,shortcode,Php,Wordpress,Api,Plugins,Shortcode,不确定是什么,但短代码中的属性没有传递给处理程序函数 Wordpress Post中的短代码 [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"]
[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
为什么零食价值没有被传递??有什么线索吗?这里是如何使用属性的短代码
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"]
您缺少提取内容以下是如何将短代码与属性一起使用
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"]
您缺少提取功能可能需要使用提取功能,如文档所示:
// [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' );
也许您需要使用提取功能,如文档所示:
// [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' );
提取方法不只是将值提取出来并转换成它们自己的值吗?我的问题是,属性似乎根本没有被传递。好吧,所以我使用了shortcode\u atts和extract。shortcode_atts正在覆盖我的值,即使它应该被传递。据我所知,shortcode_atts假定在未传递值的情况下提供默认值。问题是我正在传递一个值,但它以null的形式进入函数。extract方法不只是将值拉出并放入它们自己的值吗?我的问题是,属性似乎根本没有被传递。好吧,所以我使用了shortcode_atts和extract。shortcode_atts正在覆盖我的值,即使它应该被传递。据我所知,shortcode_atts假定在未传递值的情况下提供默认值。问题是我正在传递一个值,但它以null的形式进入函数。$atts以null的形式进入函数。所有这些都会使用默认值覆盖null值。但我正在把一些东西传递给$atts。我不明白为什么它是空的。虽然$atts是空的。所有这些都会使用默认值覆盖null值。但我正在把一些东西传递给$atts。我不明白为什么它是空的。所以我重新启动了我的计算机,它现在似乎正在工作。于是我重新启动了我的电脑,它现在似乎可以工作了。叹息