30

I've got some problems with templates in Wordpress (multisite). I've created a file in the root of my child-theme folder (template-test.php)

<?php
/**
* Template Name: Test template
*
*/
?> 

<?php get_header(); ?>

<?php get_footer(); ?>

This template is not showing up in the templates dropdown when creating a new page, or editing an existing page. The only thing in the dropdown is the 'default template'.

What I've tried so far: - Disabling and enabling my theme - Flush permalinks - Check permissions of my files - Check if style.css is in the root of the template folder (it is)

I've tried the same file on another Wordpress installation, and there it works fine.

4
  • Check if you have index.php in the root of your theme
    – Eugene
    May 1, 2017 at 8:35
  • I'm having the same issue and tried everything you mentioned. Did you ever get a solution?
    – wckronholm
    May 4, 2017 at 21:23
  • In my case i don't even see the file in the Theme Editor. @Tom have you solved it? Nov 21, 2017 at 12:42
  • 1
    I had the same thing happening (v5.4.2). It wasn't working and then it was. I had just added the line '* Template Post Type: post, page, product' which appeared to fix the issue but when I removed it, it still worked... A mystery? Caching issue of some sort maybe?
    – dra_red
    Jun 11, 2020 at 0:42

7 Answers 7

33

Just in Wordpress 4.9 there's this bug: https://core.trac.wordpress.org/ticket/42573 causing the template files to only be rescanned once every hour.

To fix (until they release a new WP version with this changed), download the patch on that bug ticket and make the changes from the patch to wp-includes/class-wp-theme.php.

Hope this saves someone the 2 hours I wasted on this..

4
  • 3
    You can also add this code to your functions.php or add it as a plugin to stop caching rather than editing core files: gist.github.com/westonruter/6c2ca0e5a4da233bf4bd88a1871dd950
    – Bradley4
    Nov 22, 2017 at 21:47
  • 8
    Another simple solution is to bump the theme version in the style.css file as pointed by @ocean90 on the forum.
    – r1987
    Nov 27, 2017 at 18:53
  • 1
    @r1987 the style.css update worked!
    – Darye
    Nov 29, 2017 at 23:31
  • For me the style.css was corrupt, so just update the file and you should be good
    – nodws
    Jun 18, 2018 at 16:02
5

Make sure you have index.php in your main theme. Main theme must have index.php. I have same issue, and this was the case. Checked by:

function testate(){
    global $wp_themes;
    $tema = wp_get_theme();
    echo '<pre>';
    print_r($tema);
    die;
}

add_action('init', 'testate' );
4

There's a bug in Wordpress 4.9.

I found this temporary plugin super straightforward. I plan on uninstalling it once they fix the bug, but it works great in the meantime!

Plugin: https://github.com/connorlacombe/WP-Clear-File-Cache

0
2

I also had this problem with a site on WordPress Multisite and was able to fix it by following these steps:

  1. Go to http://example.com/wp-admin/network/themes.php (replace example.com with your URL).
  2. Click the "Edit" link under the theme that's causing you issues.
  3. In the right sidebar click the name of the template file that's not showing up. For example, it might say "Events Page Template (template_events.php)".
  4. Don't make any edits to the file and click the blue "Update File" button.
  5. Refresh the page's edit screen where you're trying to set the template and it should now display in the dropdown.

If this doesn't do the trick for you I'd suggest checking out http://vanseodesign.com/wordpress/wp-page-templates-dropdown/. There are some other possible solutions in there.

Good luck.

1

Templates can be deactivated by unsetting them from the wp_themes global variable before the template dropdown is loaded.

Run this code on the page to see what templates show up:

global $wp_themes;
$tema = wp_get_themes();
print_r($tema["child-theme folder name"]["Template Files"]);

If your template does not show up, the parent theme might have unset it from the array.

It might show up, if you run this code in front-end, as the parent theme might only unset it during the load of the admin editor page.

Download the parent theme and search the files for $wp_themes and wp_get_themes(); to find the location of that code.

Hopefully they've given you a way to prevent it using a filter, if not you might have to re-add the files in the child theme. This could be helpful: http://www.wpexplorer.com/wordpress-page-templates-plugin/

0

Have you accidentally moved or removed the style.css file from the theme root?

If so, it could be this - recreate the themes style.css to re-enable the template dropdown.

-1

Fix page template not showing in dropdown menu please activate below plugin to fix (instead of changing wordpress core files)

Below is link for download https://drive.google.com/file/d/1ycHQGdc_vQtvtfBaznJp1KRsEbcoRwxB/view?usp=sharing

1
  • 6
    Never install a plugin from a link like this! It cannot be trusted. Always install plugins from trusted sources like the Wordpress Plugin Repository.
    – jasonlfunk
    Dec 17, 2018 at 12:12

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