1

After renaming the files of my templates and inside the file with php, it is looking for the old templates. The dropdown is no longer available. Why is this happening and how to fix that?

The only files i modified is the template-parts folder inside the child theme. I did not touch the class-wp-theme.php where it is the warning.

enter image description here

4
  • 2
    this is a known bug within WordPress 4.9 where WordPress saves the template file name and doesn't gracefully fail when the template is no longer there
    – Alex Older
    Commented Nov 22, 2017 at 9:06
  • Everything is fixed now, i just needed to wait for some reason.
    – csandreas1
    Commented Nov 22, 2017 at 10:28
  • To speed up this process you can change your theme's version because its cached with the theme version. Later you can just change it back
    – Wilco
    Commented Nov 22, 2017 at 11:03
  • @Wilco okay i will try that, the next time i may come in this problem. I hope this bug will get fixed though soon.
    – csandreas1
    Commented Nov 22, 2017 at 14:03

1 Answer 1

2

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

Hope this helps!

:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.