My articles currently have a Metatag page title [node:title]. Sometimes this results in duplicate page titles (articles can have the same title), which isn't desirable from a SEO point of view. Therefore, I would like to add a number after [node:title] when there already exists an article with the same title.

I use the Pathauto module, which adds a suffix to duplicate paths, so this suffix would be perfect. Can I use the path suffix in the Metatag page title? Or is there another possible solution?


The only token Pathauto provides is [node:url:args:join-path], the generated alias for the node. The suffix originates from, pathauto_alias_uniquify(&$alias, $source, $langcode), which Pathauto doesn't expose in any way; it's generated as needed to ensure the output alias is unique.

Theoretically, you could provide your a custom token that tries to find the value, but it would be error prone; pathauto isn't storing the suffix independently so there's no guarantee that a matched value is actually the suffix generated from Pathauto.

This is more of an editorial problem then a technical one. So a better solution would be to enforce unique titles at an authoring level.

For example, utilizing the Unique Content Title module to verify that each node title is unique upon submission.

| improve this answer | |
  • Thanks for your suggestions. However, in my particular case it really is impossible to enforce unique titles. Even if I do so, a standard title is generated with the Automatic Nodetitles module when no title has been filled in by the user. Any other ideas to cope with this issue? – Jeroen Oct 7 '16 at 23:47
  • I don't know all the particulars of your requirements so it would just be speculative guesses. However, some function is probably evoked for auto nodetitles that you can evoke during a validation handler to compare for uniqueness. – Shawn Conn Oct 11 '16 at 20:21

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.