0

I posted this question a week ago on the nodewords issue queue, but have had no reply and I'm stumped.

I want to programatically set the default value for a couple of tags, but the code comments for hook_metatags_default_values_alter read like hieroglyphics to me. An example would allow me to understand clearly. If I want to set the og:latitude tag to the value 43.701536, what should the call look like?

Thanks!

  • For future reference: it turns out the version of nodewords documented on DrupalContrib.org (3.x) didn't even exist as a download. My version included no such hook — of course I couldn't get a nonexistent hook to work! So folks, always double-check the module version when using DrupalContrib.org. – UTAN_dev Feb 20 '14 at 14:57
1

Without ever having used that hook, I would suppose that you could do it very similar to the example in the documentation for hook_metatags_default_value_alter():

function hook_metatags_default_values_alter(&$values, $parameters) {
  if ($parameters['phase'] == 'post_load' && $parameters['type'] == NODEWORDS_TYPE_USER) {
    $values['og:latitude'] = 43.701536;
  }
}

For a better understanding it might be worth the effort to dig through the code of _nodewords_tag_value which seems to have the only invocation of the hook. You can see there, that it is invoked twice with a different $phase parameter. I think I would go for post_load, assuming that the defaults are not empty.

For the type parameter, you can see the available constants in the nodewords.module doc under constants. This value depends on where you want to alter the tag.

If the above code doesn't work, use dpm or something similar to inspect the $values that are passed in. That should give you enough information concerning the expected data.

  • Indeed. And the only other comment I would add is that type included (NODEWORDS_TYPE_USER) here would restrict this to user profile pages, so, you may need to change or ignore that. All the types supported are listed at the very beginning of nodewords.module. – Jimajamma Feb 5 '14 at 14:28
  • Belated reply: thank you! Your comments were very helpful and, beyond this specific issue, gave me some great insight at how one approaches unfamiliar modules. – UTAN_dev Feb 20 '14 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.