最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

themes - Problem after renaming wordpress template file

programmeradmin0浏览0评论

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.

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.

Share Improve this question edited Nov 23, 2017 at 16:56 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Nov 22, 2017 at 9:02 csandreas1csandreas1 2063 silver badges11 bronze badges 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
Add a comment  | 

1 Answer 1

Reset to default 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/westonruter/6c2ca0e5a4da233bf4bd88a1871dd950

Hope this helps!

:)

发布评论

评论列表(0)

  1. 暂无评论