How to Create Custom Post and Page Templates in WordPress

Create Custom Post Page Templates wordpress

[vc_row][vc_column][vc_column_text]

Custom Page Templates

  • To create a new template for pages
  • Go into the theme folder of twenty-fifteen( found under wp-content/themes/twentyfifteen )
  • Create a copy of the file called page.php, and name it
  • Open it up with your favorite text editor

It should look something like this:

    • The first thing you want to do is add the following at the top of the code. Right below the PHP opening tag ( <?php )

    • So the commented area should look something like this:

  • With the code above added to the top of the code as a PHP comment
  • The template system of WordPress now recognizes this as a custom page template.
  • Go to your admin dashboard_add new/edit page section
  • You will see a new dropdown appear in the Page Attributes meta box on the right side
  • Now make the edits to the page template
  • You can edit anything in the code, as long as you have the Template Name: Roundup in the header

Custom Post Templates

  • It’s almost the same process, but you’ll need a plugin to work
  • There are two popular plugins, Custom Post Template and Single Post Template

With Custom Post Template Plugin

    • First, install it
    • Go to the page.php file and look for single.php
    • As we did for the page templates, make a copy of it, and name it
    • Open it with your favorite text editor
    • Should looks something like this:

    • Then add the following at the top. As  PHP comment.

    • After you added the php comment and installed the plugin, on the post editor, you should see a new meta box appear, titled “Post Template

    • With Single Post Template Plugin
    • Difference is the PHP Comment you have to add on the top

    • This one, adds the meta box under the editor, and not on the sides
    • Works the same as all the above

  • You can edit anything, add/remove anything
  • If you want to perform queries, you have to have either WP_Head() or wp_header() in your file

[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column][vc_column_text][Echo_Backend_SC post_id=”6646″][/vc_column_text][/vc_column][/vc_row]

Subscribe To Our Newsletter

Get updates and learn from the best