Tag Info

Hot answers tagged

8

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 ...


5

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.


3

I thought I would provide you with another approach. It is also a bit hackish, but it is general purpose and allows you to simply register the filename and label that you want to use, like so: if ( class_exists( 'WPSE_196995_Page_Templates' ) ) { WPSE_196995_Page_Templates::register_page_template( 'My Page Template', ...


1

Couple of issues are seen here - You have hooked a function in a template file whereas such code should go in functions.php instead or you can directly put the code of this function in the template. You does not seem to be getting value of $post inside this function. Both the return statements should be removed and just echo $html; should be placed just ...


1

Got around with a ugly hack :-/. I will update the answer If I go with jQuery later on. The solution still requires to have template files but code for the template file loads from the index.php I made a new template/ directory and put all page template there. All page templates are blank. We need it only for them to show up on the dropdown. Use ...



Only top voted, non community-wiki answers of a minimum length are eligible