I am following this tutorial: https://www.wpthemedetector.com/create-archives-page/

How come when I type the following block of code in a file named page-archives.php, the template name changes? For example, if I typed in "Archive2" the dropdown list would display Archive2. I thought comments didn't have any effect.


Template Name: Archives


That comment is what makes a file as a (custom) page template. Relevant excerpt from Creating Custom Page Templates for Global Use:

To create a global template, write an opening PHP comment at the top of the file that states the template’s name.

<?php /* Template Name: Example Template */ ?>

And the tutorial actually says, "the name of the template that appears in the Page Attributes section of the WordPress page editor is defined using the Template Name string".

So, whatever name you define there would be the name used in the templates dropdown. E.g. Template Name: Archive2 would assign the template name to Archive2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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