Shad Gagnon
Shad Gagnon

Reputation: 513

Wordpress page template dont appear inside Template Dropdown List

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

Answers (3)

Dylan Kinnett
Dylan Kinnett

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

kenvilar
kenvilar

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' );

Reference: Fix for theme template file caching https://gist.github.com/westonruter/6c2ca0e5a4da233bf4bd88a1871dd950

:)

Upvotes: 0

Shad Gagnon
Shad Gagnon

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

Related Questions