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

问题描述 投票:1回答:2

如何将页面标题输入到shortcode参数的值?我有自定义的php脚本编写接受参数,我可以在参数中发送硬编码的镜头作为值,但我必须在参数中发送页面的标题

php wordpress shortcode
2个回答
1
投票

发送短信代码:

[myshortcode title='Web pages']

// 短代码

function shortcode_myshortcode($atts) {

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

return  $atts['title'];

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

0
投票

不确定我理解你的问题,但要获得当前帖子的标题使用get_the_title()。您可以在短代码功能中使用它,或者在为您自定义的PHP脚本调用时。

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

© www.soinside.com 2019 - 2024. All rights reserved.