I'm not sure I've seen this exact question, but I'm curious how I can include custom and/or auto-generated parts of a slug. It's not the URI creation, but the slug itself.

For Instance:

{slug}-{id} would turn into lorem-ipsum-dolor-sit-amet-123456 on submit

and from there on the variable {{entry.url}} would be example.com/lorem-ipsum-dolor-sit-amet-123456.

I know ExpressionEngine had an option in the Channel preferences called URL Title Prefix, so this would go along those lines, but more auto-generated than a predefined set of words.

If it changes things, this is specifically for Commerce and Digital Products at the moment.

  • You can do so with Craft's Dynamic Entry Titles Commented Jun 15, 2017 at 18:54
  • craftcms.com/docs/templating/filters#kebab
    – Brad
    Commented Jun 15, 2017 at 19:25
  • I don't necessarily want the title to be dynamic. The title should be able to be populated by the user. But upon submit, or even right away when the create entry page loads, the slug should be prepended or appended by the ID. @Brad I don't know how that kebab filter helps? Commented Jun 15, 2017 at 20:30
  • Dynamic Entry Titles are dynamic in the sense saving an entry would create a slug depending on any combination of fields you want. You can set your title field to be {entry.user-entered-slug}-{entry.id} or {entry.fieldA}-{entry.fieldB}-{entry.postDate}-some-text-{entry.id} etc etc. Commented Jun 16, 2017 at 12:56
  • OK, I think I'm following. I could create a psuedo title field and behind the scenes it's populating the actual title field with the pertinent info I need. I'll try this... Commented Jun 16, 2017 at 13:26

1 Answer 1


I think for this you'd want to write a custom plugin that listened to the onSaveEntry event.

That plugin would check that the given entry is in the correct section/entry type you're interested in, pull any data from custom fields set on the entry update the slug for that entry accordingly.

I'd probably look at updating the slug directly in the database and avoid going back through craft()->entries->saveEntry() to avoid getting into an infinite save entry loop.

  • Old answer, I know, but is this something I could do easily enough with a module? - trying my hand at learning how to do it.
    – Jay
    Commented Jun 21, 2019 at 22:28

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.