如何在短代码中将页面标题作为参数发送

How to send page title as parameter in shortcode

如何将页面标题获取到短代码参数的值? 我编写了接受参数的自定义 php 脚本, 我可以在参数中发送硬编码的 shotcodes 作为值,但我必须在参数

中发送页面的标题

在短代码中发送 post 标题:

[myshortcode title='Web pages']

//简码

function shortcode_myshortcode($atts) {

$atts = shortcode_atts(
        array(
            'title' => 'no foo',            
        ), $atts);

return  $atts['title'];

}
add_shortcode('myshortcode', 'shortcode_myshortcode');

不确定我是否理解您的问题,但要获得当前 post 的标题,请使用 get_the_title()。您可以在短代码函数中使用它,或者在为您制作的自定义 php 脚本准备调用时使用它。

https://developer.wordpress.org/reference/functions/get_the_title/