Home Forums WoodMart support forum Change Blog title single post in active category name

Change Blog title single post in active category name

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #187961

    RemcoFo
    Participant

    I want to change the “Blog” title on a single post page into the active category name. I added the whole page title function in functions.php (child theme).

    // Heading for blog and archives
    		if( $single_post_design != 'large_image' && is_singular( 'post' ) || woodmart_is_blog_archive() ):
    
    			$title = ( ! empty( $page_for_posts ) ) ? get_the_title( $page_for_posts ) : esc_html__( 'Blog', 'woodmart' ) ;
    
    			
    

    I tried many things but didn’t find a good solution. Thank you for your support.

    #188080

    Artem Temos
    Keymaster

    Hello,

    Here is a code to display the active category name https://prnt.sc/s1qiex

    if ( is_singular( 'post' ) ) {
        $categories = get_the_category();
        if ( $categories ) {
            $title = $categories[0]->name;
        }
    }

    Regards

    #188944

    RemcoFo
    Participant

    That does the trick! Thank you!

    #189034

    Artem Temos
    Keymaster

    You are welcome!

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Change Blog title single post in active category name’ is closed to new replies.