Templates Hierarchy: Use IDs instead of slug

Hi,
my question seems trivial but it’s not clear to me if we can use, in our custom templates overrides, the ID of a page instead of the slug. It’s not so clear in the docs, that states:

The theme root contains files that you can further extend with the normal WordPress Template Hierarchy

Let me explain better: for example I have a page named About with id 4. I want to create a custom base.php for it. I can create base-page-about.php but it’s possible to use base-page-4.php?
This could prevent from breaking everything if the slug or the permalink change.

Thank you!

1 Like

In my experience, the ID is less ideal than the page name or slug. The ID is essentially random, it would make future troubleshooting more difficult than simply searching for page names or slugs.

However, Wordpress should recognize the ID when looking for templates. See the hierarchy here:

https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/#Custom_Page_Template

Wordpress will look for the slug, then the ID, then use the default page. I don’t believe Sage affects this functionality.

Well, I understand your point, on the other side the ID is univocal so it preserves from beak everything apart when you change slug and so.
My question is relative to the way Sage implements wordpress template hierarchy and so, if the example expressed above is valid.
Thank you :slight_smile:

Fair enough. Hope the link helped either way.

We try to stress as much as we can that Sage does not change anything at all when it comes to the WordPress template hierarchy.

Have you tried to use IDs instead of a slug, or are you just asking?

1 Like

Hi @benword thank you for your reply.
Indeed, I’m just asking, underlying the doubts I had reading the docs. Of course the trial and error path is always a good one :slight_smile: