[Solved] Hyphens instead of Underscores in Post-type Archive Template Filenames when Post-type handle contains underscore

admcfajn Asks: Hyphens instead of Underscores in Post-type Archive Template Filenames when Post-type handle contains underscore
I’m working on implementing WordPress coding standards on a theme which has several custom post-types, each of which have underscores in their handles.

The theme uses the custom post-type handle in the file-names, eg: archive-my_posttype.php for the my_posttype post-type… But WordPress coding standards require that filenames use hyphens and not underscores, ( see WordPress.Files.FileName.NotHyphenatedLowercase for more info )

I’ve changed the file-name of the archive-template to archive-my-posttype.php but I’m apprehensive because I remember this behavior didn’t exist previously.

example:​

Code:
register_post_type( 'my_posttype' /* truncated for brevity */ );

Would correspond to the template-files archive-my_posttype.php & single-my_posttype.php but not archive-my-posttype.php & single-my-posttype.php

I recall being required to use the underscores in my filenames in the past. Can anyone tell me when this was changed and if it has anything to do with the rewrite-attribute being set when the CPT is registered?

I’m happy to see that I can replace the underscores with hyphens without issue, I’m just wondering when this became not an issue & if anyone knows any other conditions of this feature that people should be aware of

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.