Change Blog title single post in active category name
-
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.
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
That does the trick! Thank you!
The topic ‘Change Blog title single post in active category name’ is closed to new replies.