Reputation: 513
I've just add a new custom template file on my WP theme folder. This new template begin like my others template files :
<?php
/*
Template Name: My Template Name
*/
Strangly, this new template do not appear inside Template Dropdown List inside admin page editing.
It seem to have a WP caching issue or something like this... I've tried to clear the cookies and cache of my browser, clear my server cache, and more... but it do not work.
Upvotes: 0
Views: 2015
Reputation: 240
For me the solution was to change the file permissions for the missing template. For some reason, the permissions were incorrect when I uploaded the file, but after changing its chmod permissions to 755, then template appeared in the dropdown as expected.
Reference: https://vanseodesign.com/wordpress/wp-page-templates-dropdown/
Upvotes: 0
Reputation: 21
If you have WP-CLI installed, try to run wp cache flush
or
you can put this code into your functions.php
function fix_template_caching( WP_Screen $current_screen ) { if ( ! in_array( $current_screen->base, array( 'post', 'edit', 'theme-editor' ), true ) ) { return; } $theme = wp_get_theme(); if ( ! $theme ) { return; } $cache_hash = md5( $theme->get_theme_root() . '/' . $theme->get_stylesheet() ); $label = sanitize_key( 'files_' . $cache_hash . '-' . $theme->get( 'Version' ) ); $transient_key = substr( $label, 0, 29 ) . md5( $label ); delete_transient( $transient_key ); } add_action( 'current_screen', 'fix_template_caching' );
:)
Upvotes: 0
Reputation: 513
After more than an hour searching the Web and testing many things, I've found that I need to change my theme version to let WP know the new files structure (inside style.css) :
/*
Theme Name: My Theme Name
Version: 1.0.0
*/
TO
/*
Theme Name: My Theme Name
Version: 1.0.1
*/
And it finally work! Hope it will help someone else ;)
Upvotes: 0