• I want to add a new CPT to a theme. I want that theme to be as “self-contained” as possible, in the event I need to activate a different theme in the future.

    The conventional way of doing that would be to add the CPT’s archive and single pages in the a child theme.

    The problem with that is that if I activate a new theme, I would have to move the templates over. If left up to a client, this would likely break their site.

    I would like to make a custom plugin to add the CPTs (easy enough), but also add the archive and single templates in the plugin directory, instead of a child theme directory.

    Is there a hook I can use that will let me add the templates in a plugin directory instead of the theme directory?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Thread Starter oguruma

    (@oguruma)

    @bcworkz From what I am reading, that’s not the right one for this use case.

    I am using the Geodirectory Plugin. With Geodirectory, you create page and the content area from that page spits put the specific content.

    So, in essence, I need to add Page templates, as in, a template you would select when using the WordPress UI to make a new page. Not necessarily a single.php

    As of now, I just have it in my child theme and commented with

    <?php
    /**
    * Template Name: Directory Single Template 1
    *
    */
    
    Moderator bcworkz

    (@bcworkz)

    If you want to be able to select a plugin’s page template from the Page Attributes editor meta box, it gets rather involved. I’ve used the following plugin code to do so in the past:
    https://pastebin.com/t5KukZL9

    Note that this code is very old, it may need adaptation to work in current WP versions.

    You must explicitly define each template file in this code, starting at line 74.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add CPT Templates somewhere other than theme directory?’ is closed to new replies.