• lfbender

    (@lfbender)


    I am trying to assign a custom single post template to a custom post type.

    The custom post type is ‘machines’. I would like that when a user opens a custom post, WordPress uses that specific template.

    After reading a bit about hierarchy I tried renaming the template file to single-machines.php, machines.php and a couple of others to make it happen but it wouldn’t take.

    What factors am I not considering?
    I am able to manually assign the template via the admin screen and it works, but I would like it to be automatic.

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

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The correct file name is indeed single-machines.php if “machines” is the registered post type slug. It is “machines” and not “machine” right? It’s common to register singular nouns and pluralize them in the labels. There is no rule against using plural slugs, it’s just not as common. You should be consistent with whatever you do to help avoid hard to find errors.

    If the template is not being used, your theme or a plugin could be interfering with the default template hierarchy. Try deactivating all plugins and switching your theme to a default twenty* theme. Locate where the machines registration code is. Temporarily copy only the registration code and the single-machines.php file to the twenty* theme you are using. The template should now be used for single machines requests. Start restoring your normal configuration, one module at a time, testing after each. When the template again fails to be used, the last activated module is the cause.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom post type with custom template’ is closed to new replies.