• What’s the best practice if you have want have one ore more custom pages in your theme?

    As far as I know, simplest is just page-slug.php example page-privacy-policy or page-terms-conditions.php. It’s easy for the developer to recognize immediately which page you are working on, but if someone changes the slug in WP Admin then the template won’t work anymore

    The other way is to us post ID example page-2334.php, but if you have many you have to open each php file to see which template it refers to

    Just wondering how other developers do this

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Slug or ID are the only options to relate a specific template name to a page. You’ve identified the drawbacks of each. There’s no best or worse choice, it’s more about what works for you. Choose your own poison ??

    There are other possibilities that do not rely on template name. You could conditionally do different things from one template based on which page was requested. For example, us a different layout for pages that are assigned a particular meta value (a.k.a. custom field).

    You can define page templates for global use where which one to use can be selected while editing the page.

    You could use the “template_include” filter to override what WP would normally do based on arbitrary criteria.

    Which of these options is “best” will vary by the situation. You know your situation best, so you’re the best judge of which approach is best for you.

Viewing 1 replies (of 1 total)
  • The topic ‘Best practice for customizing one single page’ is closed to new replies.