Can I use `.phtml` instead of `.php`

I want to use .php extension for php that have a logic like functions.php, and for a html template file .phtml.

Is there way to use .phtml instead of .php extension? For example, sidepar.phtml, page.phtml and so on.

Solutions Collecting From Web of "Can I use `.phtml` instead of `.php`"

I’m going to echo all of the above comments & say it’s not a good practice to get into. You might want to borrow a convention from the PHPTemplate library used in Drupal and call your files something.tpl.php. That way it’s still a .php file, but you have an extra extension showing it’s a template.

No, there is no such ability. Even more I wouldn’t recommend you to use .phtml extensions. Why? Because they won’t be interpreted as PHP files if you open them directly in the browser (for instance http://mysite.com/wp-content/theme/mytheme/single.phtml).

So the best practice and good habit is to use .php extension for your templates.

You can achieve this with .htaccess files by adding the line

AddHandler php-cgi .phtml

File Handling is actually done by your server and not php itself, so yes you can change the extensions to something custom.

However as stated in a comment. I would only do this if you are not going to share your themes as most people wouldn’t be able to use it.