簡體   English   中英

為自定義類別頁面添加動態標題

[英]Adding a dynamic title to custom category page

我正在使用 WooLentor 和 Elementor 制作自定義存檔/類別頁面。我真正需要的是動態標題。 我的意思是我有5個類別。 現在,如果我打開第 3 類,我希望看到第 3 號標題,如果我打開第 5 類,我希望看到標題為第 5 號。

頁 URL 是https://moja-savna.si/

希望有人設法幫助我。

親切的問候

將此添加到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] 短代碼。

謝謝你的協助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM