I realize this is a little bit of an edge case, but one I'm going to report nonetheless because I have to get it fixed even if the module itself doesn't get modified to prevent the situation.

The site I am working with is a worldwide franchising company which is creating microsites for each franchise location as well as using Domain Access to provide content to two domains (.com and .ca) for franchises in the US and Canada.

We have a set of pages which we call "services" (think services provided through the location - say "business cards", and each location needs to have what appears to be their own localized business card page though the content is the same content) that are essentially identical for each location, but the node is being served up for each microsite (with custom tokens which pull from their profile to provide city, owner, location, etc. data). A service node contains a title, a center body, and a corporate body. We are attempting to use custom location-based tokens in the metatags to create unique title tags for each center's service page. It is working fine for the description and keywords, but the system appears to be caching the tags such that once a page is viewed for one center, all the center pages contain the same data in place of the token (think [center:city] as the token which makes the title tag contain "St Louis business card printing" for a St Louis based center. Problem is once the "St Louis" part is served, every other view of the same service page, but associated with another center (say Austin) still reads "St Louis business card printing" in the Austin locations tag, even though the meta description and keywords in the code do have Austin.

I also tested this with standard Drupal tokens rather than just our custom location tokens and I've ensured my page caching on the site is turned off.

Anyone have any ideas? Is this a bug? Any workaround suggestions?

Comments

gaurav.goyal’s picture

I am having the same issue with the current page title token [current-page:title] on my multilingual site.

astanley86’s picture

Yes, I'm experiencing the same issue as Gaurav.goyal After upgrading Metatag to 7.x-1.1 the Page Title module is no longer working. It is showing [current-page:title] variable instead of the value. It looks like Tokens are no longer available to be used by the Page Title module. Installing the most recent DEV version of Metatag fixed this.

czigor’s picture

Version: 7.x-1.0-rc2 » 7.x-1.4

The problem is that metatags is caching according to the page url (see metatag_page_build()). So if the page title is dynamically set on a given url you need to do sg like this:

function MYMODULE_page_build(&$page) {
  if (request_path() == 'myurl') {
    $title = drupal_get_title();
    $page['content']['metatags']['global']['title']['#attached']['metatag_set_preprocess_variable'][0][2] = $title;
    $page['content']['metatags']['global']['title']['#attached']['metatag_set_preprocess_variable'][1][2]['title'] = $title;
  }
}

And make sure this runs after metatag_page_build().

The solution on the metatag level could be a configuration on which pages not to cache the title tag.

damienmckenna’s picture

@czigor: Metatag also considers the site's URL ($_SERVER['HTTP_HOST']) when compiling the cache IDs, so that shouldn't be necessary.

moehac’s picture

I have multiple entities running off same url, in my case /user would invoke user entity and profile2 entity based on session. Page title for /user was getting cached until I fixed it by doing the following instructions I found in the README file:

  1. Go to /admin/config/people/accounts/display
  2. Enable "Tokens" under "Custom Display Settings"
  3. Clear cache

Text in README.txt:
4. As the meta tags are output using Tokens, it may be necessary to customize
the token display for the site's entities (content types, vocabularies,
etc). To do this go to e.g., admin/structure/types/manage/article/display,
in the "Custom Display Settings" section ensure that "Tokens" is checked
(save the form if necessary), then to customize the tokens go to:
admin/structure/types/manage/article/display/token

My issue is not resolved for other meta tags on /user (example: Open Graph, Twitter card tags) which are still caching values.

elizoller’s picture

The solution at #3 worked for me. Thanks!

damienmckenna’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Category: Bug report » Support request
Status: Active » Fixed

The problem is that each URL may only be the primary location for a single entity - it isn't possible to have two different entities load from the same URL without doing something custom. What you might try doing is adding tokens to the user defaults to pull values from the Profile2 entity.

Furthermore, take a look at metatag_cache_default_cid_parts() to see what values are used to separate the caches - entity id, revision id, language code, etc. You can use hook_metatag_page_cache_cid_parts_alter() if you need to take this further, but I really don't think you should need to.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

BarisW’s picture

Thanks Damian for that tip. I used hook_views_pre_render to set the views title in code (to get a "You searched for: 'music'" title). For others who run into this:

Step 1:

<?php
    /**
     * Implements hook_views_pre_render().
     */
    function MYMODULE_views_pre_render(&$view) {
      if ($view->name == 'site_search') {
        if ($view->current_display == 'page_search') {
          $params = drupal_get_query_parameters();
          if (!empty($params['search'])) {
            // Override the search title.
            $view->set_title(t("Searched for '@terms'", array(
              '@terms' => $params['search'],
            )));
          }
        }
      }
    }

?>

Step 2:

<?php
    /**
     * Implements hook_metatag_page_cache_cid_parts_alter().
     */
    function MYMODULE_metatag_page_cache_cid_parts_alter(&$cid_parts) {
      if (current_path() == 'search') {
        $params = drupal_get_query_parameters();
        if (!empty($params['search'])) {
          $cid_parts['search_param'] = $params['search'];
        }
      }
    }
?>