Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
2  
As far as I know, interpretation of file depends on server setting that I can change myself. But if it is good practice to use .php in wordpress community, I'd use .php extension. Thanks for your reply. –  Tetsu Oct 2 '13 at 9:22
1  
Yes, it is OK if you do it for yourself. But if you will share your theme, then you can't be confident in other people hosting environments. –  Eugene Manuilov Oct 2 '13 at 9:43
    
I'd even go further, @EugeneManuilov I dont think it is a good practice within WordPress development. Because you start doing it for private use code and soon enough you will be coding for a customer or contributing to a project with these acquired routine, that doesn't fit the community best practices for WP :) –  versvs Oct 2 '13 at 16:17
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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