WordPress升级后page-{slug}.php自定义页面失效求助
page-{slug}.php Not Loading in WordPress (4.9.x) Hey there, let's work through why your custom page template page-{slug}.php stopped working—even after rolling back to WordPress 4.9.2. Here are the step-by-step fixes to get it back up and running:
1. Double-Check the Slug Match (Critical!)
First, make sure your template filename exactly matches the page's slug (not the title). For example:
- If your page's permalink is
your-site.com/contact-us/, the slug iscontact-us, so your template must be namedpage-contact-us.php. - Watch out for case sensitivity: Linux servers treat
Page-Contact-Us.phpdifferently frompage-contact-us.php, so stick to all lowercase. - You can confirm the slug by editing the page in WordPress admin—look under the "Permalink" section (click "Edit" next to the URL to see the exact slug).
2. Flush Your Permalinks
WordPress relies on rewrite rules to map URLs to templates, and these can get messed up after updates. Fix this in 2 clicks:
- Go to Settings → Permalinks in your WordPress admin.
- Don't change any settings—just click Save Changes. This regenerates your
.htaccessfile and resets the rewrite rules.
3. Check for Higher-Priority Templates
WordPress follows a strict template hierarchy, so a more specific template might be overriding your page-{slug}.php:
- If there's a
page-id-{X}.phpfile (where{X}is your page's numeric ID), this will load first. Check your page's ID in the admin (look at the URL when editing the page—it'll be something likepost.php?post=123&action=edit, so ID is 123). - Also, avoid naming conflicts with other templates like
page.phporsingular.php—though if your slug template worked before, this is less likely.
4. Verify File Location & Permissions
- Make sure
page-{slug}.phpis placed directly in your active theme's root folder (not in a subdirectory like/templates/unless you've customized the hierarchy). - Check file permissions: Set PHP files to
644and folders to755(most hosting panels let you adjust this via File Manager or FTP). If permissions are too restrictive, WordPress can't read the template.
5. Rule Out Plugin Conflicts
Plugins like cache tools, page builders, or custom template plugins can interfere with template loading. Test this:
- Disable all plugins in your admin.
- Refresh the problematic page—does the
page-{slug}.phptemplate load now? - If yes, re-enable plugins one by one until you find the conflicting one.
6. Debug Which Template Is Actually Loading
To confirm WordPress is even trying to use your slug template, add this debug code to the top of your index.php file:
<?php global $template; echo 'Current template: ' . basename($template); ?>
Visit the page, and it'll show exactly which template file is being loaded. If it's still index.php, you'll know the issue is with template detection, not the file itself.
7. Reinstall Your Theme (If Needed)
If you've ruled out all the above, your theme files might be corrupted. Try:
- Back up your current theme (save any customizations!).
- Download a fresh copy of your theme from its source.
- Replace the theme files via FTP or your hosting's File Manager.
内容的提问来源于stack exchange,提问作者YMG




