I want to use
.php extension for php that have a logic like
functions.php, and for a html template file
Is there way to use
.phtml instead of
.php extension? For example,
page.phtml and so on.
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
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.