我使用此功能获取内容区域中的帖子页面标题:
function myshortcode_title( ){
return get_the_title();
}
add_shortcode( 'page_title', 'myshortcode_title' );
所以,我有一个插件,当我在下面使用这个短代码时,它会读取短代码之间的文字:
[responsivevoice voice="UK English Male"] Wonderful World [/responsivevoice]
所以,我正在做的事情以及我的问题也是我如何才能将"页面标题短码"在responsivevoice短信中这样吗?
[responsivevoice voice="UK English Male"] [page_title] [/responsivevoice]
(它应该获得帖子页面的标题,但它不起作用)。
答案 0 :(得分:1)
选择以下选项之一,然后在以下位置添加代码段:
add_shortcode( 'page_title', 'myshortcode_title' );
选项#1: [responsivevoice2]
add_shortcode( 'responsivevoice2', 'responsivevoice2' );
function responsivevoice2( $atts = array(), $content = '' ) {
if ( $content = do_shortcode( $content ) ) {
return RV_add_bblisten( $atts, $content );
}
return '';
}
样本用法:
[responsivevoice2 voice="UK English Male"] [page_title] [/responsivevoice2]
此短代码允许您使用[page_title]
或任何其他短代码
要说的文字。
选项#2: [responsivevoice_page_title]
此Shortcode将始终使用页面标题(或当前帖子的标题)
作为要说的文字。 使用此短代码,您不需要[page_title]
短信码。
add_shortcode( 'responsivevoice_page_title', 'responsivevoice_page_title' );
function responsivevoice_page_title( $atts = array() ) {
if ( $page_title = get_the_title() ) {
return RV_add_bblisten( $atts, $page_title );
}
return '';
}
样本用法:
[responsivevoice_page_title voice="UK English Male" /]