Add custom php code in WordPress Pages using page templates

Add custom php code in WordPress Pages using page templates. If you want to add custom php code or html that you want to display, you can one of the WordPress features called WordPress Page templates.

Code to Add custom php code in WordPress Pages using page templates

Just create a page template with the below code as page-search.php

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

php get_header(); ?>

 Here's my cover page!

<?php get_footer(); ?>  

After that Assign the page with page template, Follow the below steps.
WordPress can be configured to use different Page Templates for different Pages. To select a different Page Template:

  • On the right menu, select the drop-down menu labeled “Page Template.”
  • Choose the WordPress Theme template file to be used when displaying this particular Page.

Without assigning page templates manually, The WordPress Template Hierarchy also recognizes specific Pages or Posts automatically without the need to assign them to a specific Page template file. If the Page with ID or slug in the template file name is created by the user, the appropriate Page template file is automatically used.

  • page-{id}.php
  • page-{slug}.php

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe