最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

template_listing.php:

if (!empty($offer['listingId']))
    include('include_offer.php');

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?

Edit:

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.

发布评论

评论列表(0)

  1. 暂无评论