如何将页面标题输入到shortcode参数的值?我有自定义的php脚本编写接受参数,我可以在参数中发送硬编码的镜头作为值,但我必须在参数中发送页面的标题
发送短信代码:
[myshortcode title='Web pages']
// 短代码
function shortcode_myshortcode($atts) {
$atts = shortcode_atts(
array(
'title' => 'no foo',
), $atts);
return $atts['title'];
}
add_shortcode('myshortcode', 'shortcode_myshortcode');
不确定我理解你的问题,但要获得当前帖子的标题使用get_the_title()
。您可以在短代码功能中使用它,或者在为您自定义的PHP脚本调用时。
https://developer.wordpress.org/reference/functions/get_the_title/