WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to make wordpress fall back on another template instead of single.php (8 posts)

  1. faeronsayn
    Member
    Posted 1 year ago #

    So I have a customized single.php file that I don't want wordpress to fall back on when it can't find a custom post type template.

    So basically, how can I define another template for wordpress to fall back on instead of the usual single.php?

  2. amobaroti
    Member
    Posted 1 year ago #

    I'm not sure that I understand your question.

    Although if a post does not have a custom template then it will need to use single.php. And as you have already done, customise single.php to look the way you want it when there is not custom post template.

  3. faeronsayn
    Member
    Posted 1 year ago #

    How can I make wordpress use another template as it's default one to fall back on instead of single.php.

    I don't want wordpress to use single.php when it can't find a custom template for the custom post type. I want wordpress to use another template, where can I define this?

  4. faeronsayn
    Member
    Posted 1 year ago #

    Is this a possibility or no?

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 1 year ago #

    You can add a filter to the "single_template" filter hook and change which template is used there based on whatever you like.

  6. amobaroti
    Member
    Posted 1 year ago #

    Thanks Samuel. I was going to look this up

  7. Chip Bennett
    Theme Review Admin
    Posted 1 year ago #

    Please review the Template Hierarchy for single post pages.

    If you don't want your custom post type to fall back on single.php for the single post view, you will need to define single-{posttype}.php, where {posttype} is the slug of the registered custom post type.

    If you want to have a general fallback for single post pages, and customize the single post page for blog posts, you could put that cusotmization in single-post.php, since post is the post-type slug for blog posts.

  8. faeronsayn
    Member
    Posted 1 year ago #

    Thanks, this seems to have resolved my issue, I didn't know you could actually use "single-post.php" I thought that the "single.php" was for posts. Anyway, that seems to have fixed the problem.

Topic Closed

This topic has been closed to new replies.

About this Topic