Ad last update to category-title

Posted in: Newspaper
Post count: 209

Hello,
I would like the date of the last post displayed in the category title as update info. I used a filter in my functions.php, but it seems not to work. How can I do this? Here is my code in the functions.php

function add_last_post_date_to_every_category_title($title) {
$args = array(
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'DESC'
);

$the_query = new WP_Query($args);

if ($the_query->have_posts()) {
$the_query->the_post();
$date = get_the_date();
$title .= " - Last Update: " . $date;
}

wp_reset_postdata();

return $title;
}

add_filter('get_the_archive_title', 'add_last_post_date_to_every_category_title');

Post count: 21065

Hello!

For customization and other services, you can contact our custom work team here: https://tagdiv.com/premium-customization-services/.

Thank you for understanding!

Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.