Setting URL-Key automatically

I’m setting up my first multi-language with Kirby right now. Coming from Typo3 it’s really easy and intuitive.

One thing that’s a tiny bit annoying for the panel user is the URL-Key field that has to be set manually for every page. If you want beautiful URLs instead of the default language URLs for each language at least. But I think that’s inevitable for SEO.

The “title”-field has to be set either way, so why not converting the title field automatically to an URL-Key? Just like Kirby does when you create a new page?

Could I insert that in the blueprint?

Thank you,
Thomas

3 Likes

That is a good idea! :slight_smile:

Did you open a issue over on github about this, so that i gets seen? :smiley:

You can achieve this by using a panel hook in site/config/config.php

kirby()->hook('panel.page.update', function($page) {
  try {
    $page->update(array(
      'URL-Key' => str::slug($page->title()),
    ));
  } catch(Exception $e) {
    echo $e->getMessage();
  }
  return;
});

There are some Problems

  • It only works with languages which are not the default languages (as discussed here).
  • The URL-Key gets updated each time the title is changed. Why? You can’t use panel.page.create because this hook is fired when you change the language in the panel to create the page in the new language and at this moment the fields are prepopulated with the values from the default language. And this leads to an url key in the wrong (default) language …

But it was fun to check this out :smile:

2 Likes

It would still be a decent default fallback in the absence of a SEO Slug field (URL-Key) -great one @flokosiol :ok_hand:

By the way: which absence? There’s a link in the sidebar on every page to change the slug for each language individually. And this gets saved to the content file as URL-Key.

:laughing: actually, I really don’t know what i was thinking about.

tracking main language is possible…

1 Like