Cannot add custom page template to my child theme - wordpress

I'm running Wordpress 3.3.1.
I'm writing a child theme that modifies the default twentyeleven theme. Everything seems normal, except that when I add a custom page template, it doesn't appear in the add/edit screen (so I can't use it!).
To elaborate on "normal", here's what IS working:
My child theme appears and activates normally.
My CSS code (in style.css) is appearing.
My files from the template hierarchy are working (ex: front-page.php, page.php)
I've read and reread the codex, and my custom page template file ("coming-soon.php") seems to have the correct header:
<?php
/*
Template Name: Coming Soon
*/
So why won't it show up under the "Template" drop-down???
I've added custom templates dozens of times and never had this problem. The only possible difference I can think of is that I'm writing a child theme (even though the codex says this shouldn't matter), or perhaps it's a difference in the newest update of WP.

I can't duplicate what you're seeing with a clean install of WordPress 3.3.1. I have a theme with just two files, style.css, containing:
/*
Theme Name: stackoverflow-8946077
Template: twentyeleven
Version: 0.0.1
*/
#import url("../twentyeleven/style.css");
and coming-soon.php, containing:
<?php
/*
Template Name: Coming Soon
*/
get_header();
?><h1>Coming Soon</h1><?php
get_footer();
?>
the first part of which was copied from your question.
I see the template as expected:
The only things I can think of are to double-check:
the file exists on the server you're running on
the file's in the child template's directory (though it should work if it's in the twentyeleven directory)
there's no file with the same name in the twentyeleven directory, which (I think) would take precedence
the file name ends in .php
you only have a single space between "Template" and "Name:" (the regex used contains the literal Template Name:)
Failing that, the dropdown is populated by the get_page_templates function in wp-admin/includes/theme.php. Might be worth sticking some debug code in there to see if the $templates variable includes coming-soon.php.

This is an old thread. But if anyone is looking for solutions now, it may be the issue in WP 4.9. More details: Templates not working properly

In my situation, it ended up being the file permissions. I set it to 755 or whatever the standard WP permission is (in regards to security) and it worked!

Mine also ended up being the file permissions.
I set it to 777, and it worked like a charm!

Related

Drupal basic page doesn’t seem to use page.tpl.php

Title says it really. Basic pages created in Drupal don’t seem to use the page.tpl.php file as a template.
If I edit the html.tpl.php file, those changes apply to every page, and it causes errors when I load a basic page.
I have also tried to copy the page.tpl.php file and name it page—basic-page.tpl.php to no avail.
Any idea what’s going on?
Also, how do I go about changing the page_top variable to include more content?
Lastly, the default page.tpl.php file has $page variables and things like $page_top and the like.
How would I call the title from the page only and the body text of a page only?
I’m using Drupal 7 and a custom sub theme.
The aforementioned files are in the template folder of the theme and I did clear caches when I added them.
Add $conf['theme_debug'] = TRUE; in settings.php and clear cache, reload page and check view source.
It will display the template file suggestions.
page.tpl.php file common for all pages. Just print anything to the tpl and run any node of basic page as well as other content type page and check if its working or not. If page.tpl.php not working for basic page only, then check your template.php file.
For print a page title just need to use following code:
<?php print $title; ?>
For print body text you need to use following:
<?php print render($page['content']); ?>
This may depend on the theme you are using. But I guess you are actually meaning page--page.tpl.php (double dashes). Which will be taken into account after you added the following snippet to your theme's template.php. Replace MYTHEME with your theme's machine name.
function MYTHEME_preprocess_page(&$variables) {
if (isset($variables['node']->type)) {
// If the content type's machine name is "my_machine_name" the file
// name will be "page--my-machine-name.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type; // (double underscores)
}
}
See Template (theme hook) suggestions, where I also got above snippet from.
active theme debug for inspecting the template source and you get a different suggestions to user it (just avoid using node/nid).
commend drush to enable theme debug drush vset theme_debug 1

Wordpress template list not showing up in posts

I'm facing a very common problem with Wordpress, I don't see the list of my templates in the post edit page. There are tons of posts about this here but I haven't found the solution to my problem in any of them.
I basically have this in my theme directory: index.php, page.php, header.php, functions.php, sidebar.php, style.css
in page.php and index.php, I have:
/*
Template Name: HOME
*/
and
/*
Template Name: PAGE
*/
What I've already tried:
- switched back to the original Wordpress theme and back to mine
- made sure permission 755 was attributed to folder
- copied a working file from another theme and inserted my code into it
- completely logged out and came back
but nothing worked, I still don't see the list of templates for my theme while for official themes, I do see the list of page templates.
Any suggestions?
Thanks
Laurent
You cannot use index.php or page.php as a Page Template, because those files are reserved for other templates of a theme.
As the Page Template reference states:
Name your template file so you can easily identify its Template Name, e.g., filename my-custom-page.php for template name "My Custom Page". Some coders group their templates with a filename prefix, such as page_my-custom-page.php (Don't use page- prefix as WordPress will interpret the file as a specialized page template.)
For information on Theme file-naming conventions and filenames you cannot use, see reserved Theme filenames.

Buddypress template hierarchy is not being used

I am updating an installation of buddypress (1.5) to the most recent version (2.1.1). I have updated the files and am now trying to update the theme to use the template hierarchy pattern.
For this I created the following directory structure within my theme:
my-theme/
buddypress/
groups/
index-directory.php
index-directory.php contains a single die('debug') statement for testing.
If I copy this buddypress directory into the twentyfourteen directory and activate that theme, I am seeing the debug message when I'm on the group listing page. However, when I use my custom theme, the message is not showing up.
This tells me that the template hierarchy is not being applied on my theme. Why could that be?
I suspect that somehow my theme is being treated as a legacy theme, I don't understand why though. I commented out the whole functions.php to make sure it's not because of aynthing in there. The header comment in the style.css does not contain anything special either.
Any help on this?
Thanks.
The problem was my own mistake. Our theme stylesheet had a Template: bp-default in it. I didn’t notice it at first because our theme is named similarly and my mind read it as the title of our theme. If I remove it, my templates are included.
For anyone stumbling on this problem in the future, here are the reasons why the template hierarchy could be deactivated by Buddypress:
Theme compat is disabled when a theme meets one of the following criteria:
1) It declares BP support with add_theme_support( 'buddypress' )
2) It is bp-default, or a child theme of bp-default
3) A legacy template is found at members/members-loop.php. This is a
fallback check for themes that were derived from bp-default, and have
not been updated for BP 1.7+; we make the assumption that any theme in
this category will have the members-loop.php template, and so use its
presence as an indicator that theme compatibility is not required
https://buddypress.org/support/topic/default-theme-is-still-showing/

admin template selection is missing on page creation in wordpress 3.2.x

I am using WordPress 3.2.1 ,
Page template selection drop down is missing on Pages (Add,Edit)
wp-admin > Pages >Add New > Page Attributes
I Edit the Template Page Default page as below code
/*
Template Name: New Template
*/
But still the template drop down no visible , my older version of WordPress it display by default.
Following is the screen shot for more idea
I solved this problem solved by adding the typical following code:
/*
Template Name: Custom
*/
Don't add any spaces after Name:
It'll work if you use template name: as well.
It might help someone: check if your index.php file is in place.
If it's not there, wordpress treats the template as corrupt and it doesn't display the template selection.
This should be simple to troubleshoot. The requirements for the page template to work are straight forward:
The template needs the page title in the top of the file like you've shown (the title needs to be wrapped in a PHP tag, you probably just didn't add it with your example bu I want to make sure you havne't overlooked it):
<?php
/*
Template Name: Custom
*/
?>
The second requirement is that the file is in the root of the theme folder.
With those two requirements in place, it should work. If it isn't working you nave a few possible issues. I list a few off the top of my head:
You might need to re-install WordPress in-case a file was corrupted
during your last update.
It's possible someone has altered the WP-Admin layout using users
roles.
That's all I can thing of at the moment, let me know how it turns out.
I had the same issue. It actually turned out to be a missing style.css file within the template directory in my case.
This happens because the get_post_templates() in class-wp-theme.php first checks for errors. If it finds any then it returns an empty array (no templates are displayed).
A side effect of this is that saving a page would clear the existing template and use the page.php instead.
So in short if the errors() method of your theme returns any errors then no templates dropdown.
hope that helps someone.
Same issued, I found out that in appearance panel in your WordPress dashboard the stylesheet is missing. You shouldn't rename the style.css in your theme folder.
Not sure if this will help anyone, but we solved the problem by disabling our theme and re-enabling it again. We had some other theme folders in the theme directory that we weren't using so we deleted those out as well. good luck, it's a really random problem to solve!
yeah!template dropdown not showing because you have no template So how to solve this::---
1 create template folder in theme
2 create a template in this folder
like:-
<?php /* Template Name: Home */ echo "template"; ?>
and check-in page dropdown will be there.

Template Dropdown not showing up within Wordpress administrator page

I am working on a Wordpress-based project, and I just added a new template to the installation by uploading a template file. I was creating a new page that will use my new template, when suddenly, the "Template" dropdown in the "Page Attributes" box is gone.
I am using Wordpress 3.0.1.
Update:
I saw a site which told me to revert to the default template, and back to my custom template. Apparently it worked, but I am still baffled on what triggers this bug. Also, any additional knowledge or pointers on this bug would be a great help since my job requires me to patch this (and possibly submit the bug fix to Wordpress). Thanks!
If you have disabled or removed the style.css from the template directory then also it will not work.
So there must be the style.css on template directory then the templates directory will be shown. When you try to remove the style.css from the template directory or using style.css from css folder, then you must be put one style.css on template directory.
Thanks
Morichika is spot on. I had the same problem, but then it sorted itself out by doing:
<?php
/**
* Template Name: Front Page
*/
?>
I have found a different solution for this. I reactivated my custom theme but then problem persisted.. then in the top most section of the code for the custom page template where it actually defines the name of the template like this:
<?php
/*
Template Name: Front Page
*/
?>
I did this:
<?php
/**
* Template Name: Front Page
*/
?>
Then refreshed the admin panel and it appeared.Seems a bit weird but it worked for me. Feel happy to share this.
I tried many of the suggested answers. None worked in my case.
A possible reason for the Template Dropdown not showing is a missing index.php in your Theme folder.
Just create an empty one, in case your hierarchy does not need one. But the existance of that file enables the option to choose the page template and suppresses an error message in the Choose-Theme page btw
Put style.css in your theme directory, instead of the css folder. Or
<?php
/*
Template Name: Front Page
*/
?>
There must not space between "Template Name:".
I managed to fix this by making sure the style.css in the theme root contained the theme comments. I deleted the whole stylesheet and it removed the templates dropdown.
Put this at the top of your theme root's style.css.
/wp-content/themes/YOUR_THEME/style.css
/*
Theme Name: Twenty Thirteen
Theme URI: http://wordpress.org/themes/twentythirteen
Author: the WordPress team
Author URI: http://wordpress.org/
Description: The 2013 theme for WordPress takes us back to the blog, featuring a full range of post formats, each displayed beautifully in their own unique way. Design details abound, starting with a vibrant color scheme and matching header images, beautiful typography and icons, and a flexible layout that looks great on any device, big or small.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready
Text Domain: twentythirteen
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/
https://codex.wordpress.org/Theme_Development#Theme_Stylesheet
Or if you have a custom theme...
/*
Theme Name: My Wordpress Theme
Theme URI: https://example.tk
Author: Me
Author URI: https://example.tk
Description: This is my custom theme
Version: 1.0
*/
I know is super late for this question, but I fix it adding
Version: 0.1 alpha
in the comments of the themeFolder/style.css
This is my style.css complete for my theme
/*
Theme Name: Stockout Theme
Theme URI: http://stockout.com.uy/myTheme
Author: MauriPastorini
Author URI: http://stockout.com.uy
Description: This is a theme for stockout page
Version: 0.1 alpha
*/
I hope someone find this useful
I had the exact same problem with WordPress 3.2.1. I added a new template and the menu disappeared from the page add/edit screen. The solution was to switch back to the default twentyeleven theme end then right back to my custom theme. The templates drop-down began appearing again.
BTW, you said "revert to the default template, and back to my custom template" but I'm pretty sure you meant theme. I'm guessing where you saw this was here:
http://wordpress.org/support/topic/template-file-drop-down-not-appearing
Looks like this bug has existed for a couple of years at least. I filed a report:
http://core.trac.wordpress.org/ticket/18324
Try this. template will be available for both page & post
<?php
/**
* Template Name: Blog Post
* Template Post Type: post, page
?>
In WordPress 5.8 they have moved the selectable custom templates out from under the Page Attributes section so no matter what you do you won't find it there (even if you spend 2hrs troubleshooting like I did, lol).
Custom selectable templates have now been moved into their own box call "Template". For me, it was at the top of my right-hand sidebar in the WP admin page editor. It's possible it may not show if it has been unchecked in your screen options settings which are now found under the three dots in top-right --> Preferences --> Panels --> Ensure "Templates" is checked.
I'm not sure if I just overlooked it for 2hrs straight or if it appeared only after I changed to a different theme then changed back.
I had this problem a while back and found one janky solution after a lot of search--sometimes switching to another theme in your install and then switching back to you primary theme will make your templates appear. I know that sounds weird, but worked for me for a while.
I've had this problem for two days. This forum and a couple of tests later did the work. Here is what was missing for my part.
Be sure that there is a style.css in your theme folder.
The style.css must have a valid comment section at the top of the file.
This means at least this:
/*!
Template: your-theme
*/
If you're using SASS or LESS, make sure that you have a "!" just after declaring your comment. It's to prevent SASS or LESS to delete your comment section.
To be sure that everything is settled fine. You may go to "Appearance > Themes". After the listing of themes, if there is nothing, than everything should be fine. Otherwise, it'll be written "Broken Themes" and you'll still have some issues to solve.
sass had deleted the content in my child style.css. The template drop down shows again once I added back the comments.
/*
Theme Name: Sometheme Child
Description: Child theme for Sometheme.
Template: sometheme
Version: 1.1
Text Domain: sometheme-child
*/
You will not see the dropdown if you have added 0 custom template files in your theme root.
When at least 1 template is available, the WordPress ecosystem picks it up and the dropdown will become visible.
Add this in your theme root to try it.
<?php
/*
Template Name: Front Page
*/
The Template Dropdown is now moved To Page Section and is located just between the Static and Visibility and Permalinks dropdown. But you will be able to see it if you are naming your custom file like
page-Yourfilename.php
and adding a comment on the top of the file
<?php
/*
Template Name: YOUR TEMPLATE NAME
*/
?>
I was just facing the same issue so, the problem is in spacing between 'Template Name' and that colon.
/*
Template Name: template-name
*/
Make sure there is no spacing before the colon.
I found the root of the problem.
It is the style.css file inside the theme root.
It must be in "UNIX encoding".
It must have all comments with "Theme Name", "Version", etc.
Jack Nicholson was right! You need to make sure your style.css contains the full comment. Example below:
Previously mine was:
/*
Theme Name: Acadata
Theme URI: https://www.factorypattern.co.uk
Description: Custom
Author: Factory Pattern
Version: 1
License: GNU General Public License
License URI: license.txt
*/
Then I changed it to the below and now I can see all my templates.
/*
Theme Name: Acadata
Theme URI: https://factorypattern.co.uk/
Description: Custom
Author: Factory Pattern
Author URI: https://factorypattern.co.uk/
Description: The Acadata theme for WordPress.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready
Text Domain: acadata
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/
Please set properly you style.css file specially if you are working on child-theme
/*
Theme Name: Theme Name
Theme URI: http: //mysite.com/
Description: This is a custom child theme for xxx theme
Author: My Name
Author URI: http: //mysite.com/
Template: template_name_in_lowercase
Version: 0.1
*/
This below is work for me and show template option in page attributes.Just place .php file in theme root folder.
<?php
/* template name: my custom template */
?>
There are a lot of great answers on this question, but one obvious solution, which initially escaped me, was to double-check that in Dashboard > Settings > Reading you want to set "Your homepage displays" to "Static Page" and then leave the "Posts Page" unselected.
While themes and a properly coded theme file play a role in the situation, the reason that the page attributes area on the edit page screen doesn't show the templates drop-down may be because you selected a particular page to be your "Posts Page", and so WordPress is not asking you for a custom template to use because it's already using front-page.php or home.php (See WordPress Template Visual Hierarchy).
Hope this helps someone like me who had a properly coded template file but didn't realize this setting had been selected.
This was also a problem for me and it was because of folder structure. The Theme Handbook told me a should organize my theme folder and files like so:
assets (dir)
- css (dir)
- images (dir)
- js (dir)
inc (dir)
template-parts (dir)
- footer (dir)
- header (dir)
- navigation (dir)
- page (dir)
- post (dir)
404.php
archive.php
comments.php
footer.php
front-page.php
function.php
header.php
index.php
page.php
README.txt
rtl.css
screenshot.png
search.php
searchform.php
sidebar.php
single.php
style.php
The page template I was trying to load was in /template-parts/page/template-contactus.php
I guess that was too deep for WordPress so I got ride of those directories and now my file structure looks like this:
assets (dir)
- css (dir)
- images (dir)
- js (dir)
inc (dir)
template-parts (dir)
- section-content.php
- template-contactus.php
404.php
archive.php
comments.php
footer.php
front-page.php
function.php
header.php
index.php
page.php
README.txt
rtl.css
screenshot.png
search.php
searchform.php
sidebar.php
single.php
style.php
I am now able to see the template drop-down and add templates.
Hope this helps someone.
In my case, I had called the template schedule-template-v2.php which won't work, the file name needs to be schedulev2-template.php. A simple mistake.
In addition to all of the above, make sure that you have 'page attributes' checked in the screen options panel in the top right, otherwise the page attributes section wont show regardless.
If you are trying todo with blog page the GOTO Dashboard > settings > and remove post page from select menu :)
After searching I have found a stupid solution that was obvious because. Couldn't catch it because the templates were put in other place of interface attaching screenshot

Resources