【问题标题】:Adding a dynamic title to custom category page为自定义类别页面添加动态标题
【发布时间】:2022-01-09 19:14:30
【问题描述】:

我正在使用 WooLentor 和 Elementor 制作自定义存档/类别页面。我真正需要的是动态标题。我的意思是我有5个类别。现在,如果我打开第 3 类,我希望看到第 3 号标题,如果我打开第 5 类,我希望看到标题为第 5 号。

【问题讨论】:

    标签: dynamic categories title archive titlebar


    【解决方案1】:

    将此添加到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' );
    

    之后只需使用 [page_title] 短代码。

    谢谢你帮助我

    【讨论】:

      猜你喜欢
      • 2019-05-21
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 2014-04-14
      相关资源
      最近更新 更多