Skip to content

Make blog entry slug editable for SEO optimization#48

Merged
7underlines merged 10 commits intomainfrom
copilot/make-slug-editable
Dec 30, 2025
Merged

Make blog entry slug editable for SEO optimization#48
7underlines merged 10 commits intomainfrom
copilot/make-slug-editable

Conversation

Copy link
Contributor

Copilot AI commented Dec 23, 2025

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)

  • Removed disabled attribute from slug input field

Controller Logic (werkl-blog-detail/index.js)

  • Added state tracking: slugManuallyEdited, autoGeneratedSlug, isAutoGenerating
  • Modified generateSlug() to set isAutoGenerating flag during updates, storing result in autoGeneratedSlug
  • Updated slug watcher to detect manual edits only when not auto-generating and value differs from autoGeneratedSlug
  • Modified onBlogTitleChanged() to skip auto-generation when slug is manually edited
  • Set slugManuallyEdited=true when loading existing entries to preserve URL stability

SEO URL Route (BlogSeoUrlRoute.php)

  • Changed DEFAULT_TEMPLATE to use entry.translated.slug instead of entry.translated.title
  • Ensures that custom slugs are used when generating frontend URLs

Migration (Migration1735580257UpdateSeoUrlTemplateToUseSlug.php)

  • Updates the SEO URL template in the database to use slug instead of title
  • Handles both old template format (blog/{{ entry.translated.title|lower }}) and new format (blog/{{ entry.blogCategories.first.translated.name|lower }}/{{ entry.translated.title|lower }})
  • Triggers automatic regeneration of all blog entry SEO URLs when the plugin is updated
  • Ensures existing installations get the updated template

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:

  1. Run bin/console system:update --finish to execute the migration
  2. All SEO URLs for blog entries will be regenerated to use the slug field
  3. Old URLs will remain as redirects (Shopware's default behavior)
  4. New custom slugs will immediately work in the frontend
// Title change triggers auto-generation only if not manually edited
if (!this.blog.slug || !this.slugManuallyEdited) {
    this.generateSlug(blogTitle);
}
// SEO URL template now uses slug instead of title
'blog/{{ entry.blogCategories.first.translated.name|lower }}/{{ entry.translated.slug|lower }}'
Original prompt

This section details on the original issue you should resolve

<issue_title>Feature Request: Slug bearbeitbar machen</issue_title>
<issue_description>SEO-Technisch ist es meist nicht so toll, den Slug genau wie den Beitragstitel aufzubauen.
Bearbeitbar wäre klasse. Also beim Anlegen automatisch generieren, dann aber zur Bearbeitung freigeben.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits December 23, 2025 18:50
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>
Copilot AI changed the title [WIP] Add functionality to make slug editable Make blog entry slug editable for SEO optimization Dec 23, 2025
Copilot AI requested a review from 7underlines December 23, 2025 18:58
@7underlines
Copy link
Member

Editing the slug in the backend works, but in the frontend the new url does not work.

@7underlines
Copy link
Member

@copilot
Editing the slug in the backend works, but in the frontend the new url does not work.

Co-authored-by: 7underlines <17121556+7underlines@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 29, 2025

@copilot
Editing the slug in the backend works, but in the frontend the new url does not work.

Fixed in commit 0e10d73. The issue was that the SEO URL template was using entry.translated.title instead of entry.translated.slug.

Changed the DEFAULT_TEMPLATE in BlogSeoUrlRoute.php to use the slug field:

'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.

@7underlines
Copy link
Member

@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.

Copilot AI and others added 2 commits December 30, 2025 17:50
Co-authored-by: 7underlines <17121556+7underlines@users.noreply.github.com>
Co-authored-by: 7underlines <17121556+7underlines@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 30, 2025

@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.

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:

  • Old: blog/{{ entry.translated.title|lower }}blog/{{ entry.translated.slug|lower }}
  • New: blog/.../{{ entry.translated.title|lower }}blog/.../{{ entry.translated.slug|lower }}

After running bin/console system:update --finish, all blog entry SEO URLs will be regenerated to use the slug field. This will make the custom slugs work in the frontend, and the links on listing pages will use the new slugs.

@7underlines 7underlines marked this pull request as ready for review December 30, 2025 19:40
@7underlines 7underlines merged commit cc55042 into main Dec 30, 2025
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Slug bearbeitbar machen

2 participants