WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.51k stars 4.2k forks source link

Allow slug edit for Template Part and Template post types #57629

Open webmandesign opened 10 months ago

webmandesign commented 10 months ago

What problem does this address?

When creating a user/custom Template Part or Template in Site Editor, it seems I am not able to set up custom slug for these.

Usecase:

  1. My theme contains template hierarchy for search results. It displays a generic search results template when no post_type query parameter is set. But it displays search-jetpack-portfolio.html template when post_type parameter is defined (and set with jetpack-portfolio value) in search.
    If I use WordPress in English, I can live with setting up "Search Jetpack Portfolio" title/name for my custom created Template for displaying search results for jetpack-portfolio post type, although it is not ideal solution. The "Search Jetpack Portfolio" produces search-jetpack-portfolio slug for the Template, so the theme recognizes it and applies my custom template when Jetpack Portfolio post type is being searched.
    But if I use WordPress in different language, the slug is produced from the title I type in in such language and it is different than theme required search-jetpack-portfolio slug.
    Currently there seems to be no way for me to adapt my custom template slug.

  2. Other usecase could be when I create a custom Template Part and name it "Posts list: With sidebar", but I would like to apply query-sidebar slug to it (possibly just due to my OCD :) ).

What is your proposed solution?

It would be great if there was some option field to edit slug for Template Part and Template post type. Something like:

template-part-slug

talldan commented 10 months ago

A problem with editing the slug for template parts is that it breaks the connection to any template part block that references it. In order to make slug changes a reality any instance of template parts every instance of a template part would also need to be updated. That is possible, though I'm not sure that it's on a roadmap.

I think it has some relation to this issue - Reusable blocks and Template Parts isolated editing view: Add menu in top toolbar for navigating to usage locations, since both require being able to search across a site for template part usage.

Template parts also use the slug to maintain a connection to the theme provided template part (for the customization and 'clear customizations' feature), so that's another area that would need some thought.

I'm not sure if there are any similar constraints for templates.

webmandesign commented 10 months ago

@talldan Thanks for the valuable feedback.

Indeed, this would cause issues. User would need to take this in consideration when editing the slug then. But I may be biased as I am a theme developer, so I am OK with it, though I understand it can cause confusion for users that don't understand why their template part references stopped working suddenly. Maybe a description/note for such slug edit option would do here?

Alternatively, could a slug edit option be available when define( 'WP_DEVELOPMENT_MODE', 'theme/all' ); is defined in wp-config.php file? It would be beneficial when theme developers build their theme in Site Editor.

As for the theme provided template parts issue: I would only like to edit the slug when creating a custom, user-defined template part, not when editing the theme one. I think this is doable as themes define their template parts via theme.json file (or they are recognized as a files in theme's parts folder), so WordPress already knows the difference - which template part is the theme one and which is the user/custom one.

talldan commented 10 months ago

Interesting suggestions.

It could also be in the scope for a plugin like Create Block Theme if it's primarily for theme builders. Have you used that before?

There's an issue tracker here for that plugin.

What do you think?

webmandesign commented 10 months ago

I've used the Create Block Theme plugin before, but I no longer use it. I prefer to build my theme in code editor and then test and do finishing steps in Site Editor. That's when I came across the need described in this issue.

But I'm not against the toggle option for this in the plugin, so I'll check it out. Thanks.