Wordpress - What is singular.php?
It's the nature of the WordPress template hierarchy - point being, if you don't have a page.php
, it will use singular.php
, same if you don't have single.php
, it will fallback to a template lower in the hierarchy.
Ideal for themes that have the same layout for posts/pages, instead of having duplicate code in each respective template.
singular.php
is basically an extra fallback for all post types, regardless if built-in or custom. It comes in straight after single.php
and page.php
, so you can omit the latter two templates and just have a singular.php
template which will be used by all post types in single view.
How useful it will be and the necessity of it will, just as with any other template, depend on the user/site/requirements. The template hierarchy is built such that, regardless of any page being viewed, you will always just need index.php
to display any page. So in short, you can have a fully functional theme with only index.php
and style.css
in the theme folder.
The templates available in the template hierarchy are just there for convenience, and that goes for singular.php
as well. You can use any template in context if you need to, but you don't have to use it if you don't need it.
The single post template file is used to render a single post. WordPress uses the following path:
1.single-{post-type}.php – First, WordPress looks for a template for the specific post type. For example, post type is product, WordPress would look for single-product.php.
2.single.php – WordPress then falls back to single.php.
3.singular.php – Then it falls back to singular.php.
4.index.php – Finally, as mentioned above, WordPress ultimately falls back to index.php.
https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
The template file used to render a static page (page post-type). Note that unlike other post-types, page is special to WordPress and uses the following patch:
1.custom template file – The page template assigned to the page. See get_page_templates().
2.page-{slug}.php – If the page slug is recent-news, WordPress will look to use page-recent-news.php.
3.page-{id}.php – If the page ID is 6, WordPress will look to use page-6.php.
4.page.php
5.singular.php
6.index.php
https://developer.wordpress.org/themes/basics/template-hierarchy/#page