Hi there,
I am using the Enfold Avia ‘Blog Post’ content element to display posts from categories. For single post pages, I would like to change the default title on single.php blog pages from ‘Blog – Latest News’ to the category in which the post belongs.
I have copied single.php to my child theme to edit, and understand I need to change the line:
$title = __('Blog - Latest News', 'avia_framework'); //default blog title
to use something like this instead:
<?php the_category(' '); ?>
but I’m just not quite sure if that is correct/where to put it/how to get it to work and keep the existing formatting. Your guidance is appreciated!
– Jill
Hey Jill!
Try the following:
$title = get_the_category();
Best regards,
Josue
Hi Josue,
Tried that and it returns the text “Array” rather than the category. Other ideas? thanks, Jill
Hi,
Can you create an administrator account and post it here as a private reply?
Regards,
Josue
Hey Jill!
The server user didn’t work. i can’t access your site.
Best regards,
Josue
Hi!
Try to replace
$title = __('Blog - Latest News', 'avia_framework'); //default blog title
with
$categories = get_the_category();
$title = '';
if($categories){
foreach($categories as $category) {
$title .= $category->cat_name . ' ';
}
}
Best regards,
Peter
Thank you, Peter, that worked perfectly!
Regards, Jill