I am going through an online Udemy course alongside it I'm building my own little website.

The website has 4 pages 1 of them a front page that I've created front-page.php and the rest of the pages will be using the page.php template but different content embedded in them.

My plan is to have the page.php call the relevant content based on the page-id for instance for a warranty page the code would look like this.


get_template_part( 'template-parts/content', get_the_ID());

//getting the content from templates based on ID?>


get_template_part( 'template-parts/content', get_the_title());

//And get the content based on the title of the page

so I guess my question is, is this the correct way of doing this or how else more efficient way would you go about doing this?


  • depends on the complexity and differences in content and structure of what you are trying to output per page. you also could work with individual files page-{slug}.php as per developer.wordpress.org/themes/template-files-section/… .. also depends on how much of the content should be editable from within the normal page text editor.
    – Michael
    Commented Jan 25, 2020 at 22:18

1 Answer 1


Neither is correct. page.php is a generic template that will be used for any page, automatically. You don't need to manually get the correct page content, you just need to use the correct template tags and WordPress will automatically output the correct values for the current page.

<?php the_title(); ?>
<?php the_content(); ?>

WordPress templates are templates. You don't need a file for every piece of content, or to manually populate them with the correct content. You just need to define the structure of the content with HTML, and use the template tags to indicate where the page-specific content goes.

All that get_template_part( 'template-parts/content' ) does is include the template-parts/content.php template into the current template. This allows you to break down templates into smaller parts, to make them easier to manage. So you only need one template-parts/content.php file, and you would use the template tags I mentioned above in that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.