php – Change title and meta description in included page (not template)

I’m trying to change title and meta description for pages used for products.
The goal is to have the same effect as here:
<script>document.title = "<?php echo $new_title; ?>";</script>

The page with lists of products is a template where are includes in some conditions.


if (!empty($offer('listingId')))

I’m struggling with how to change title/description in include_offer.php.
My findings so far:

function wp1_filter_wp_title($title) {

if (is_page_template('include_offer.php')) {
    return 'some title';
return $title;
add_filter('pre_get_document_title', 'wp1_filter_wp_title');

But it doesn’t work. It’s working only if if (is_page_template('template_listing.php')).
Is there any function like ‘is_page_template’ which also works for included pages?


function show_template() {
global $template;
echo basename($template);

basename on that single product page return ‘template_listing.php’

I also figured out there is function get_included_files but I’m not sure how to use that in my case.