wordpress if is not page template
- Open the theme's folder in your WordPress installation directory.
- Locate the "page.php" file within the theme folder.
- Duplicate the "page.php" file and rename the duplicate as "template-custom.php" (replace "custom" with your desired template name).
- Open the "template-custom.php" file in a code editor.
- Locate the following code within the file:
<?php
if (have_posts()) :
while (have_posts()) : the_post();
// The content of the page
endwhile;
endif;
?>
- Replace the existing code with:
<?php
/*
* Template Name: Custom Template
* Template Post Type: page
*/
// Your custom template content here
?>
- Save the changes to the "template-custom.php" file.
- Go to your WordPress admin dashboard.
- Create or edit a page where you want to apply the custom template.
- In the Page Attributes meta box, you should now see a "Template" dropdown.
- Select "Custom Template" (or the name you used) from the dropdown.
- Update or publish the page to apply the custom template.
Note: Ensure that you have a backup of your theme files before making any changes.