Since Wordpress 6.5 was released it seems that the assignment of templates created by code with "Template Name:" is no longer available. Is there a way to resolve the issue?
I'll explain.
On the FTP, inside the child theme of Twenty Twenty-Two, I create a file called template-about.php The code inside the file is as follows
In the backoffice, in the Pages section (with Gutengerg), up to version 6.4.4 of Wordpress, the section with all the templates created by code was shown.
From version 6.5+, when I create a new page the templates section shows the following options, and if I click on "Select Template" only the two basic templates of the Twenty Twenty-Two theme are shown.
Additionally, all previously created pages that were assigned a template, in version 6.4.4, no longer show the template select.
Answers
It seems like there might have been changes in how WordPress handles custom page templates in version 6.5. To resolve the issue and ensure that your custom page templates are recognized and selectable in the WordPress admin, you can try the following steps:
-
Ensure Proper File Structure: Make sure that your custom page template file (
template-about.php
in this case) is located in the root directory of your child theme. WordPress expects custom page templates to be located in the root directory of the active theme or child theme. -
Template Name Comment: Ensure that your custom page template file contains the required comment at the beginning, indicating the template name. The comment should be formatted as follows:
/* Template Name: Custom Template Name */
Ensure that the comment is placed at the very beginning of the file, before any other code or whitespace.
-
Check for Errors: Double-check your custom page template file for any syntax errors or issues that might prevent WordPress from recognizing it as a valid template file. Common issues include missing or misplaced PHP tags (
<?php ?>
) or incorrect comment syntax. -
Theme Compatibility: Ensure that your child theme is compatible with the latest version of WordPress (6.5+). If your child theme relies on outdated or deprecated features, it might not function correctly with newer WordPress versions.
-
Flush Rewrite Rules: Sometimes, changes to custom page templates may not take effect immediately due to cached rewrite rules. To refresh the rewrite rules, you can go to Settings > Permalinks in the WordPress admin and simply click the "Save Changes" button without making any modifications.
-
Test with Default Theme: Temporarily switch to a default WordPress theme (e.g., Twenty Twenty-Two) to see if the issue persists. This can help determine if the problem is specific to your child theme or if it's a broader issue with WordPress itself.
By following these steps, you should be able to resolve the issue and ensure that your custom page templates are recognized and selectable in the WordPress admin interface. If the problem persists, you may need to further investigate any changes or updates made to your WordPress installation or child theme.