0

I've got one specific node where I need to dynamically set the meta title. The logic to determine the correct title is too involved to express in tokens; I need to do it in code.

It seems that I should be able to override the title using the hook_preprocess_html; I get the current title, and replace it with the proper title.

After I set the title here though, the Metatag module (8.x-1.26) waltzes in, and replaces my meticulously assembled title by its own fairly generic pattern generated title. I suppose I could try using the same hooks that Metatag uses to try to outsmart it, but that seems like a fragile approach.

Is there a better way, maybe through Metatag itself?

2

1 Answer 1

0

The best solution in my case turned out to be to simply override the value of the 'current-page:title' token. This is the token I used in my metatags pattern, and could be easily overriden in hook_tokens_alter.

Other solutions I tried which worked to some degree:

  • Using hook_metatags_alter to override the metatags
  • Hijacking the _title_callback on the entity.node.canonincal route

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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