Issue with Wordpress 6.5 and custom code template

ghz 8months ago ⋅ 75 views

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

enter image description here

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.

enter image description here

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.

enter image description here

Additionally, all previously created pages that were assigned a template, in version 6.4.4, no longer show the template select.

enter image description here

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.