0

I am building a theme (parent theme) and I was advised to put custom page templates in theme root folder. I am copying theme twenty fourteen and found this theme using a separate directory called page-templates for keeping custom page templates but it does not work with my theme?

Can i know why twenty fourteen doing this and how ? Do I need to do the same because this is WordPress theme and I think they do everything thing in a proper way.

  • 1
    The WordPress Handbook says: WordPress recognizes the subfolder page-templates. Therefore, it’s a good idea to store your global page templates in this folder to help keep them organized. - - - This may mean that it's an issues with how you're setting up your templates, are you adding the comments as seen here? – Howdy_McGee Jun 2 '16 at 15:39
  • how dumb i am :( checking then whats wrong. – Maria Jun 2 '16 at 15:46
1

Where to put custom page templates in theme?

Custom page templates in page-templates folder are automatically recognized by WordPress.This folder is recommended for global or multi-purpose page-templates.

You can check more organizing theme files on theme development handbook.

but it does not work with my theme?

Are you sure you have template files with the correct header ?

0

You can put custom page template in theme: create "templates" folder in theme and put the page. First you check the admin panel and create new page display template name in "Page Attributes", like:

enter image description here

If is not, then open archive.php in given this line:

<?php
/**
 * The template for displaying Archive pages
 *
 * Used to display archive-type pages if nothing more specific matches a query.
 * For example, puts together date-based pages if no date.php file exists.
 *
 * If you'd like to further customize these archive views, you may create a
 * new template file for each specific one. For example, Twenty Thirteen
 * already has tag.php for Tag archives, category.php for Category archives,
 * and author.php for Author archives.
 *
 * @link http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Thirteen
 * @since Twenty Thirteen 1.0
 */

Replace This Line

<?php 
/*
Template Name: About Us
*/

and Refresh your admin panel, creating the new page.

Remember for all created custom page templates, make sure to write the code:

<?php 
/*
Template Name: Contact Us
*/
0

Put Template name (should be separate name) on page template php file (on toop). like this:

<?php /* Template Name: Page Template Name */ ?>

your file name can be template-your_template_name.php in theme folder or in subfolder in your theme folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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