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