pages - Custom templates not showing up in template dropdown

admin2025-06-03  0

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.

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.

Share Improve this question asked Jan 8, 2017 at 22:46 TomTom 3151 gold badge3 silver badges6 bronze badges 4
  • Check if you have index.php in the root of your theme – Eugene Commented May 1, 2017 at 8:35
  • I'm having the same issue and tried everything you mentioned. Did you ever get a solution? – wckronholm Commented 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? – Ofir Baruch Commented Nov 21, 2017 at 12:42
  • 2 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 Commented Jun 11, 2020 at 0:42
Add a comment  | 

7 Answers 7

Reset to default 33

Just in Wordpress 4.9 there's this bug: https://core.trac.wordpress/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..

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

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/connorlacombe/WP-Clear-File-Cache

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/wordpress-page-templates-plugin/

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/wp-admin/network/themes.php (replace example 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/wordpress/wp-page-templates-dropdown/. There are some other possible solutions in there.

Good luck.

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.

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/file/d/1ycHQGdc_vQtvtfBaznJp1KRsEbcoRwxB/view?usp=sharing

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748880965a314496.html

最新回复(0)