Make blog entry slug editable for SEO optimization#48
Conversation
Co-authored-by: 7underlines <17121556+7underlines@users.noreply.github.com>
Co-authored-by: 7underlines <17121556+7underlines@users.noreply.github.com>
Co-authored-by: 7underlines <17121556+7underlines@users.noreply.github.com>
|
Editing the slug in the backend works, but in the frontend the new url does not work. |
|
@copilot |
Co-authored-by: 7underlines <17121556+7underlines@users.noreply.github.com>
Fixed in commit 0e10d73. The issue was that the SEO URL template was using Changed the DEFAULT_TEMPLATE in 'blog/{{ entry.blogCategories.first.translated.name|lower }}/{{ entry.translated.slug|lower }}'Now when you edit the slug in the backend and save, the SEO URL will be regenerated using your custom slug, and the frontend URL will work correctly. |
|
@copilot In frontend I still get NotFoundHttpException if I enter the new url manually into the address bar and the links on the blog listing page also still link to the old slug. |
Co-authored-by: 7underlines <17121556+7underlines@users.noreply.github.com>
Co-authored-by: 7underlines <17121556+7underlines@users.noreply.github.com>
Fixed in commits 5c9b671 and 5a76740. The issue was that changing the code constant doesn't update the database. Created a migration that updates the SEO URL template in the database to use the slug field instead of title. The migration handles both template formats:
After running |
The slug field was disabled, preventing users from customizing URLs for SEO. The field now auto-generates on creation but allows manual editing, with subsequent title changes not overwriting manual edits. Custom slugs are now properly reflected in frontend URLs.
Changes
Template (
werkl-cms-sidebar.html.twig)disabledattribute from slug input fieldController Logic (
werkl-blog-detail/index.js)slugManuallyEdited,autoGeneratedSlug,isAutoGeneratinggenerateSlug()to setisAutoGeneratingflag during updates, storing result inautoGeneratedSlugautoGeneratedSlugonBlogTitleChanged()to skip auto-generation when slug is manually editedslugManuallyEdited=truewhen loading existing entries to preserve URL stabilitySEO URL Route (
BlogSeoUrlRoute.php)entry.translated.sluginstead ofentry.translated.titleMigration (
Migration1735580257UpdateSeoUrlTemplateToUseSlug.php)blog/{{ entry.translated.title|lower }}) and new format (blog/{{ entry.blogCategories.first.translated.name|lower }}/{{ entry.translated.title|lower }})Behavior
New entries: Slug auto-generates from title. Manual edits stop auto-generation. Frontend URLs use the custom slug.
Existing entries: Slug remains stable regardless of title changes. Manual edits allowed anytime. Frontend URLs update to reflect the custom slug.
Installation/Update Instructions
After updating to this version:
bin/console system:update --finishto execute the migrationOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.