There's a "hook_metatag_alter" mentioned in metatag_hook_info() but the corresponding drupal_alter() doesn't exist so there's no way to alter Metatags without hacking the module.

Could we please add this?

Comments

alexweber’s picture

Status: Active » Needs review
StatusFileSize
new1.34 KB

Attached is a simple patch which adds a drupal_alter() both when loading the metatag to add to preprocess and also when viewing in the admin overview page.

API docs were also updated to demonstrate.

damienmckenna’s picture

Please explain exactly what you're trying to alter as I'm a little confused as to your needs. Thanks.

alexweber’s picture

@DamienMcKenna I'm trying to alter a metatag's value before getting displayed (post-token replacement).

Basically if the pattern is set to: "[current-page:title] | [site:name]", it will resolve to "Page Title | Site Name". I have a specific use-case for a project where they want to be able to dynamically alter the metatag in certain situations. So, for the sake of simplicity, if its node/1 the title will instead be "Foo | Site Name".

Granted this is a very specific use-case, but that doesn't change the fact that, going with the Drupal way of doing things, it would be nice to have an "alter" hook for metatags. The fact that there's actually a "metatag_alter" described in "metatag_hook_info()" seems to corroborate that this was, in fact, planned.

However, despite being mentioned in hook_hook_info(), there is nowhere in the code that allows metatags to be altered (strangely enough except for taxonomy terms where theres a hook_metatag_view_alter() implemented).

Therefore, all I did was add a drupal_alter() in 2 places in the code that allows modules to alter metatags.

Does this make sense?

damienmckenna’s picture

StatusFileSize
new901 bytes

You should be using hook_metatag_metatags_view_alter() to modify meta tags, fyi this function is loaded . You can use theme functions (!) if you need to override individual meta tags one at a time.

I've added the missing $instance value to the drupal_alter call (#1818240: Add $instance to drupal_alter(metatag_metatags_view)), so here's some documentation.

damienmckenna’s picture

Status: Needs review » Fixed

I've committed the patch from #4.

alexweber’s picture

Thanks!

damienmckenna’s picture

damienmckenna’s picture

Status: Fixed » Closed (fixed)

This has been released in 1.0-beta2: http://drupal.org/node/1826908