Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I use hook_metatag_metatags_view_alter to alter the canonical metatag, it works as planned on Dev but not on prod.
I guess it has something to do with cache, but I can't figure out how to deal with it.
This is the code I use:
function mymodule_metatag_metatags_view_alter(&$output, $instance, $options) {
if ($instance == 'specific_entity') {
$url_relative = token_replace('[current-page:url:relative]');
$canonical_scheme = 'https://mycanonicaldomain.com' . $url_relative;
$output['canonical']['#attached']['drupal_add_html_head'][0][0]['#value'] = $canonical_scheme;
}
}
Thanks for any clues.
Comments
Comment #2
zuernBernhard CreditAttribution: zuernBernhard at UEBERBIT GmbH commentedDo you have some kind of page cache on the production site ?
Comment #3
zuernBernhard CreditAttribution: zuernBernhard at UEBERBIT GmbH commentedDo you have "cacheing" active for your View ?
Comment #4
pedrospI am using this hook to alter the metatag when displaying the view operation of an Entity Object (ECK entity), not a View (as for Views).
Entity Cache is activated
On admin/config/development/performance
CACHING
YES Cache pages for anonymous users
YES Cache blocks
none: Minimum cache lifetime
none: Expiration of cached pages
BANDWIDTH OPTIMIZATION
YES Compress cached pages
YES Aggregate and compress CSS files
YES Aggregate Javascript files
X AUTOLOAD
(All options disabled)
Using AdvAgg also, but there is a lot of options, please tell if relevant.
Thanks for the support.
Comment #5
DamienMcKennaIs there a difference in the Metatag settings between dev and prod?
Comment #6
pedrospSOLVED
i use Features to roll-out config and variables but I missed on admin/config/search/metatags/settings :
Master Controls for all entities: Those specific ECK entities was disabled on PROD (and enabled on DEV)
I feel dumb to missed that :|
Thanks for the tip Damien.
Comment #7
DamienMcKennaI'm just glad you got to the bottom of it :-)