[wp-trac] [WordPress Trac] #43563: Custom Page Template not working if page slug name is too short
WordPress Trac
noreply at wordpress.org
Fri Dec 18 19:11:21 UTC 2020
#43563: Custom Page Template not working if page slug name is too short
-------------------------------+-----------------------
Reporter: richardevcom | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Posts, Post Types | Version: 4.9.4
Severity: normal | Resolution: invalid
Keywords: reporter-feedback | Focuses: template
-------------------------------+-----------------------
Changes (by hellofromTonya):
* status: new => closed
* resolution: => invalid
* milestone: Awaiting Review =>
Comment:
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 [https://developer.wordpress.org/themes/template-files-section/page-
template-files/#creating-custom-page-templates-for-global-use 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 be `template-
darbi.php`
- Create a `templates` folder in the theme's root to hold all of your
templates. Then name the file the same as the `Template 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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43563#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list