带有参数的简码,但没有属性


Shortcode with parametar, but no attribute

标题可能听起来有点奇怪,对此感到抱歉。

我必须使用类似于这个(简化)的 shorcode:

[name=John]

返回"嗨约翰"。

我知道如果短代码是我会怎么做

[name first="John"]

但是在我的第一个示例中,是否有可能在代码中以某种方式获得值"John"?

我尝试使用

$a=shortcode_atts(array(
    'name'      => '',
), $atts);

但这没有用。

根据文档,您可以做的最接近的事情是

// Usage [name]John[/name] will give: Hi John.
function name_shortcode( $atts, $content = null ) {
    return 'Hi '. $content .'.';
}
add_shortcode( 'name', 'name_shortcode' );

你可以有属性,但我认为这与你的意思非常接近。