[英]Adding a dynamic title to custom category page
I'm making a custom archive / category page using WooLentor and Elementor.The only thing I really need is a dynamic title.我正在使用 WooLentor 和 Elementor 制作自定义存档/类别页面。我真正需要的是动态标题。 What I mean by that is that I have 5 categories.我的意思是我有5个类别。 Now, if I open category 3, I would want to see title Number 3, and if I open category 5, I would want a title saying Number 5.现在,如果我打开第 3 类,我希望看到第 3 号标题,如果我打开第 5 类,我希望看到标题为第 5 号。
Page URL is https://moja-savna.si/页 URL 是https://moja-savna.si/
Hope someone manages to help me out.希望有人设法帮助我。
Kind regards亲切的问候
Added this to functions.php:将此添加到functions.php:
function page_title_sc( ) {
$title = ('Page Title');
if ( is_page() || is_singular() ) {
$title = single_post_title();
} else if ( is_category() ) {
$title = single_cat_title( '', false );
} else if ( is_tag() ) {
$title = single_tag_title( '', false );
} else if ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} else if ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} else if ( is_tax() ) {
$title = single_term_title( '', false );
}
return apply_filters( 'page_title_sc', $title );
}
add_shortcode( 'page_title', 'page_title_sc' );
After that just use [page_title] shortcode.之后只需使用 [page_title] 短代码。
Thanks for helping me out谢谢你的协助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.