![](/img/trans.png)
[英]How to include page title of wordpress post in the content possibly with a shortcode
[英]How to include the post title in the post content in wordpress?
如果帖子标题是“概念”,我希望帖子内容是“在“帖子标题”中的东西”,那么我们会遵循“帖子标题”高质量政策来关注客户满意度,因此我希望帖子内容包括“概念”并将其替换为帖子标题,我认为wordpress shortcode api可以做到这一点。 但是我不知道怎么办?
我不完全理解你的说法。 但是我认为wordpress hook可以帮助您做到这一点,您可以尝试以下方式:
function change_post_title ( $post_title ) {
if ( $post_title == 'conecpts' ) {
$title = 'The new title';
return $title;
}
return $post_title;
}
add_filter('the_title', 'change_post_title');
如果标题是“ concepts”,这会将帖子标题更改为“新帖子标题”
请明确您的问题是什么,您要完成什么。
在您的帖子内容中,您需要在要打印标题的位置添加一个简短代码,下面的简短代码示例将使用[post_title]
。
function post_title_shortcode( $atts ){
extract( shortcode_atts( array(
'post_id' => get_the_ID()
), $atts ) );
return get_the_title( $post_id );
}
add_shortcode( 'post_title', 'post_title_shortcode' );
使用该简码,您可以传递帖子ID,这样,如果要获取其他帖子的标题,则可以使用简码[bartag post_id="123"]
,其中123是要显示的标题的帖子ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.