How to Create Custom Post and Page Templates in 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][vc_row][vc_column width="1/3"][mpc_icon_column preset="mpc_preset_65" border_css="border-radius:20px;" padding_css="padding:0px;" title_font_preset="mpc_preset_20" title_font_color="#444444" title_font_size="17" title_font_line_height="1.4" title_font_transform="uppercase" title_font_align="center" title="Small jobs, large jobs, anything in between" content_font_preset="mpc_preset_1" content_font_color="#888888" content_font_size="14" content_font_line_height="1.5" content_font_align="center" mpc_icon__icon="etl etl-trophy" mpc_icon__icon_color="#7bdae5" mpc_icon__icon_size="48" mpc_icon__border_css="border-radius:0px;" mpc_icon__padding_divider="true" mpc_icon__padding_css="padding-top:8px;padding-right:8px;padding-bottom:8px;padding-left:8px;" mpc_icon__margin_divider="true" mpc_icon__margin_css="margin-top:0px;margin-right:0px;margin-bottom:8px;margin-left:0px;" mpc_icon__hover_icon_color="#ffffff" mpc_icon__hover_background_color="#7bdae5" mpc_icon__hover_border_css="border-radius:50px;" mpc_divider__disable="true" mpc_divider__width="10" mpc_divider__align="left" mpc_divider__content_padding_divider="true" mpc_divider__content_padding_css="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;" mpc_divider__lines_color="#dddddd" mpc_divider__padding_divider="true" mpc_divider__padding_css="padding-top:3px;padding-bottom:3px;"][/mpc_icon_column][/vc_column][vc_column width="1/3"][mpc_icon_column preset="mpc_preset_65" border_css="border-radius:20px;" padding_css="padding:0px;" title_font_preset="mpc_preset_20" title_font_color="#444444" title_font_size="17" title_font_line_height="1.4" title_font_transform="uppercase" title_font_align="center" title="Jobs that are on fixed price, or hourly terms" content_font_preset="mpc_preset_1" content_font_color="#888888" content_font_size="14" content_font_line_height="1.5" content_font_align="center" mpc_icon__icon="etl etl-clock" mpc_icon__icon_color="#7bdae5" mpc_icon__icon_size="48" mpc_icon__border_css="border-radius:0px;" mpc_icon__padding_divider="true" mpc_icon__padding_css="padding-top:8px;padding-right:8px;padding-bottom:8px;padding-left:8px;" mpc_icon__margin_divider="true" mpc_icon__margin_css="margin-top:0px;margin-right:0px;margin-bottom:8px;margin-left:0px;" mpc_icon__hover_icon_color="#ffffff" mpc_icon__hover_background_color="#7bdae5" mpc_icon__hover_border_css="border-radius:50px;" mpc_divider__disable="true" mpc_divider__width="10" mpc_divider__align="left" mpc_divider__content_padding_divider="true" mpc_divider__content_padding_css="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;" mpc_divider__lines_color="#dddddd" mpc_divider__padding_divider="true" mpc_divider__padding_css="padding-top:3px;padding-bottom:3px;"][/mpc_icon_column][/vc_column][vc_column width="1/3"][mpc_icon_column preset="mpc_preset_65" border_css="border-radius:20px;" padding_css="padding:0px;" title_font_preset="mpc_preset_20" title_font_color="#444444" title_font_size="17" title_font_line_height="1.4" title_font_transform="uppercase" title_font_align="center" title="Work that requires specific skill sets, costs, or scheduling requirements." content_font_preset="mpc_preset_1" content_font_color="#888888" content_font_size="14" content_font_line_height="1.5" content_font_align="center" mpc_icon__icon="etl etl-newspaper" mpc_icon__icon_color="#7bdae5" mpc_icon__icon_size="48" mpc_icon__border_css="border-radius:0px;" mpc_icon__padding_divider="true" mpc_icon__padding_css="padding-top:8px;padding-right:8px;padding-bottom:8px;padding-left:8px;" mpc_icon__margin_divider="true" mpc_icon__margin_css="margin-top:0px;margin-right:0px;margin-bottom:8px;margin-left:0px;" mpc_icon__hover_icon_color="#ffffff" mpc_icon__hover_background_color="#7bdae5" mpc_icon__hover_border_css="border-radius:50px;" mpc_divider__disable="true" mpc_divider__width="10" mpc_divider__align="left" mpc_divider__content_padding_divider="true" mpc_divider__content_padding_css="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;" mpc_divider__lines_color="#dddddd" mpc_divider__padding_divider="true" mpc_divider__padding_css="padding-top:3px;padding-bottom:3px;"][/mpc_icon_column][/vc_column][/vc_row][vc_row][vc_column][vc_empty_space][/vc_column][/vc_row][vc_row][vc_column width="1/2"][mpc_textblock content_width="80" font_color="#21c5ba" font_size="80" font_line_height="1" font_transform="none" font_align="right"]

DISCOVER

[/mpc_textblock][mpc_textblock content_width="80" font_color="#333333" font_size="15" font_line_height="1.3" font_transform="none" font_align="right" margin_divider="true" margin_css="margin-top:10px;margin-bottom:10px;"]A SMARTER APPROACH TO BUSINESS GROWTH[/mpc_textblock][mpc_divider width="30" align="right" lines_color="#21c5ba" lines_weight="4" margin_divider="true" margin_css="margin-top:20px;" animation_loop_type="callout.pulse" animation_loop_duration="1000" animation_loop_delay="1000"][vc_empty_space][vc_row_inner][vc_column_inner width="1/2"][/vc_column_inner][vc_column_inner width="1/2"][mpc_counter preset="mpc_preset_1" layout="style_6" alignment="right" icon_vertical="middle" title_font_preset="mpc_preset_44" title_font_color="#888888" title_font_size="20" title_font_line_height="1" title_font_transform="uppercase" title="Permanent" counter_font_preset="mpc_preset_5" counter_font_color="#555555" counter_font_size="44" counter_font_line_height="1.5" value="8" duration="4000" delay="0" padding_css="padding:0px;" margin_css="margin:0px;" mpc_icon__icon="etl etl-profile-male" mpc_icon__icon_color="#21c5ba" mpc_icon__icon_size="60" mpc_icon__padding_divider="true" mpc_icon__padding_css="padding-right:20px;"][vc_empty_space][mpc_counter preset="mpc_preset_1" layout="style_6" alignment="right" icon_vertical="middle" title_font_preset="mpc_preset_44" title_font_color="#888888" title_font_size="20" title_font_line_height="1" title_font_transform="uppercase" title="Retainer" counter_font_preset="mpc_preset_5" counter_font_color="#555555" counter_font_size="44" counter_font_line_height="1.5" value="19" duration="4000" delay="0" padding_css="padding:0px;" margin_css="margin:0px;" mpc_icon__icon="etl etl-briefcase" mpc_icon__icon_color="#21c5ba" mpc_icon__icon_size="60" mpc_icon__padding_divider="true" mpc_icon__padding_css="padding-right:20px;"][vc_empty_space][mpc_counter preset="mpc_preset_1" layout="style_6" alignment="right" icon_vertical="middle" title_font_preset="mpc_preset_44" title_font_color="#888888" title_font_size="20" title_font_line_height="1" title_font_transform="uppercase" title="Projects" counter_font_preset="mpc_preset_5" counter_font_color="#555555" counter_font_size="44" counter_font_line_height="1.5" value="231" duration="4000" delay="0" padding_css="padding:0px;" margin_css="margin:0px;" mpc_icon__icon="etl etl-layers" mpc_icon__icon_color="#21c5ba" mpc_icon__icon_size="60" mpc_icon__padding_divider="true" mpc_icon__padding_css="padding-right:20px;"][vc_empty_space][mpc_counter preset="mpc_preset_1" layout="style_6" alignment="right" icon_vertical="middle" title_font_preset="mpc_preset_44" title_font_color="#888888" title_font_size="20" title_font_line_height="1" title_font_transform="uppercase" title="Consultations" counter_font_preset="mpc_preset_5" counter_font_color="#555555" counter_font_size="44" counter_font_line_height="1.5" value="1192" duration="4000" delay="0" padding_css="padding:0px;" margin_css="margin:0px;" mpc_icon__icon="etl etl-chat" mpc_icon__icon_color="#21c5ba" mpc_icon__icon_size="60" mpc_icon__padding_divider="true" mpc_icon__padding_css="padding-right:20px;"][/vc_column_inner][/vc_row_inner][/vc_column][vc_column width="1/2"][mpc_textblock content_width="100" margin_divider="true" mpc_tooltip__border_divider="true" mpc_tooltip__padding_divider="true"]
[/mpc_textblock][vc_empty_space][/vc_column][/vc_row][/vc_column_text][/vc_column][/vc_row]