0

So I have a custom post type that is called recipe and then I have a page called /recipes/ - What would be the proper way to hook a template for my recipes page?

I have the file single-recipe.php following the WordPress hierarchy with this inside:

<?php

/*
Template Name: Recipe
Template Post Type: post, page
*/

echo 'Hello';

But I'm not getting any templating output:
enter image description here

The below is my folder structure:

enter image description here

0

1 Answer 1

1

The filename single-recipe.php is telling WordPress "only use this file to display single 'recipe' CPT posts."

If you want to use it as a Page template, you can either rename the file tpl-recipe.php (or something similar, it doesn't have to be this filename, it just has to not be a recognized pattern like single-cptslug.php) - in which case you'll have to manually choose that template every time you create a new Recipe -

Or, you can have two files. One named single-recipe.php which does NOT have the comments at the top, and one named tpl-recipe.php (or similar) which DOES have the comments at the top.

1
  • Ahh, I thought it had to be a WordPress hierarchy template name, thanks a bunch @WebElaine - I'll rename it soon.
    – DevSem
    Commented Feb 12, 2020 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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