phpwordpress

How can I include template from lib folder to the theme?


I am creating my own WordPress theme in which I create a lib folder where I put my page template (ex page-feedback.php,page-contact.php). By doing this my whole theme is messed up. The problem is that the template that is present inside the lib folder is not getting loaded. So, how could I import that template from the lib folder to my theme?


Solution

  • The template files with the given default template naming such as (page-about.php, archive.php, taxonomy.php, etc.) must always be placed on the theme home directory so that wordpress engine can fetch them.

    But if you want to organize your page templates (only page templates) then there is a way. Add the following lines at the beginning of the template file you want to create and name the files the way you want (such as about_template.php, contact_template.php, etc). Place these files on any folder you want (inside the theme home directory).

    <?php
        /**
         * Template Name: Template Name //change this name to the name you want
         *
         * @package WordPress
         * @subpackage Twenty_Fourteen
         * @since Twenty Fourteen 1.0
         */
    

    Once you have done so, go the Add New Pages on your dashboard and attach the template to the page.

    Wordpress Developer Resources::

    Organizing Template Files

    Template Hierarchy

    Page Templates