#43563 closed defect (bug) (invalid)
Custom Page Template not working if page slug name is too short
Reported by: | richardevcom | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.9.4 |
Component: | Posts, Post Types | Keywords: | reporter-feedback |
Focuses: | template | Cc: |
Description
Hi.
I was trying to create Custom Page Template named "Darbi". I created page-darbi.php template file, added Template name: Darbi comment line and then assigned the tempalate in page editor, but after save nothing changed and page was returning index.php.
I was digging around and when I changed the page slug name to 6+ characters long it worked so my guess is that the issue is with page slug name length and custom page template functionality.
I haven't tested this on earlier versions but in stackoverflow.com there were similar issues with versions 4.7 and up.
Change History (7)
#3
follow-up:
↓ 5
@
7 years ago
- Keywords reporter-feedback added
Hi @richardevcom, welcome to WordPress Trac! Thanks for the report.
Does it still happen with all plugins disabled and a default theme (Twenty Seventeen) activated?
#4
in reply to:
↑ 1
@
7 years ago
Replying to mukesh27:
it's working fine even if i rename Page Template Name to single alphabet "D" try to install new WordPress then check.
did you try both slug & template for ex. 5 characters long?
#5
in reply to:
↑ 3
@
7 years ago
Replying to SergeyBiryukov:
Hi @richardevcom, welcome to WordPress Trac! Thanks for the report.
Does it still happen with all plugins disabled and a default theme (Twenty Seventeen) activated?
Yes. Disabled all the plugins. Haven't tried with Twenty Seventeen them instead. I'll update you.
#6
@
4 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
Hello @richardevcom,
You've created a global custom page template and assigned it via the Page Attributes
UI in the editor to at least one page.
The problem is related to the template's file name. Global templates should named without using the page-
prefix. Why?
As noted in the documentation:
Important! Do not use page- as a prefix, as WordPress will interpret the file as a specialized template, meant to apply to only one page on your site.
That prefix page-
means WordPress is looking for a page named with darbi
slug, such as https://example.com/darbi
. page-
relates to a specific web page. For example, if there was an About Us page and its slug was about
, then the page could have a specific page template by naming the template file page-about.php
.
Does that make sense?
Common approaches are:
- Prefix it with
template-
meaning the filename would betemplate-darbi.php
- Create a
templates
folder in the theme's root to hold all of your templates. Then name the file the same as theTemplate Name
, e.g.templates/darbi.php
.
I'm marking this ticket as a close
candidate. However, feel free to reopen if this issue still exists for you today.
#7
@
4 years ago
@hellofromTonya this was posted about 4.9.4 version. Since version 5.* I haven't stumbled upon this issue anymore.
Also, no, it doesn't make sense for older WP versions (4.9.* example). The issue was well known and it was due to page template suffix name length. I think there are couple of Stack Overflow posts about this (around the time the same version was the stable one).
it's working fine even if i rename Page Template Name to single alphabet "D" try to install new WordPress then check.