• Resolved ocaso

    (@ocaso)


    I would like to set a template, which created in the WordPress Full Site Editor as the default template for a Custom Post Type. It’s important that I would like to set it as default for Custom Post Types, every Custom Post Type (for example Movies) should automatically use this template. The problem is that this template was created in the Full Site Editor, so there is no .php file.

    Thank you for help!

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi!

    There is no way to set one template as default for every custom post type, and only custom post types, via the interface. Each will need their own template.

    This is because the WordPress template hierarchy has no unique fallback template for custom post types.

    https://developer.www.ads-software.com/themes/basics/template-hierarchy/#single-post

    If the post type specific template doesn’t exist, WordPress will use the “single” template so it will be the same template that is used by posts.

    Thank you for your help, @poena. I am going to mark this one as resolved.

    Thread Starter ocaso

    (@ocaso)

    I don’t want set a template for all CPT.

    For example I made a ‘Movie’ template, and I would like to set this ‘Movie’ template for all ‘Movies’ Custom Post Type.

    But I made this template with Full Site Editor, so there is no .php template file, where I can set this for post types.

    Mmmm… @poena, just as a hypothesis, would it be possible to write a custom function that is loaded when a new custom post type is created and that checks for the CPTs slug to automatically assign one of the existing templates?

    I think I understand. There is no way to “convert” a custom template automatically. The post type must be chosen on template creation.

    Please try this:
    Copy all blocks from the template you created.

    1) Make sure the post type is registered; this is needed to ensure the Site Editor finds it.
    2) Go to Appearance > Editor > Templates
    3) Select “Add new template”
    4) In the modal, select the post type in the list.
    If it asks if you want to create a template for a single movie, or all movies, select all.
    5) Paste/ re-add the blocks in the new template.
    6) Test the template by creating a new movie post.


    If you are looking for a code solution, yes, there are ways to add templates to custom post types during or after registration, but I have never tried it with a template that is already created in the Site Editor.

    https://developer.www.ads-software.com/block-editor/reference-guides/block-api/block-templates/#custom-post-types

    Thank you so much @poena!

    I hope that helps, @ocaso ??

    Thread Starter ocaso

    (@ocaso)

    1) Make sure the post type is registered; this is needed to ensure the Site Editor finds it.
    2) Go to Appearance > Editor > Templates
    3) Select “Add new template”
    4) In the modal, select the post type in the list.
    If it asks if you want to create a template for a single movie, or all movies, select all.
    5) Paste/ re-add the blocks in the new template.
    6) Test the template by creating a new movie post.

    It’s working perfectly. Thank you very much!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to set default template for custom post type with Twenty Twenty-Three’ is closed to new replies.