• Resolved ninsan

    (@jennyrigsjo)


    Good afternoon!

    For organizational purposes I would like to store my custom templates in a directory other than the default ‘/themes/yourtheme/ultimate-member/templates/’ directory. Is this at all possible? I know there’s a filter ‘um_get_template’ but I am not sure how to use it to tell the UM plugin to look for the requested template in a different folder (say wp-content/mu-plugins/um-templates/, for instance).

    Any help would be much appreciated.

    Cheers!

    /jenny

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Aswin Giri

    (@aswingiri)

    @jennyrigsjo um_get_template hook only seems to work with UM profile tabs template. If you are looking to add a custom template for other pages like login, register, profile, account, etc, the plugin does not have any hook for now.

    @jennyrigsjo

    It’s very easy if you read this article in the documentation:

    https://docs.ultimatemember.com/article/1516-templates-map

    `How to Edit Files

    Edit files in an upgrade-safe way using overrides. Copy the template into a directory within your theme named /ultimate-member keeping the file structure according to templates map.

    Example: To override the member directory base template, copy: wp-content/plugins/ultimate-member/templates/members.php to wp-content/themes/yourtheme/ultimate-member/templates/members.php

    The copied file will now override the Ultimate Member default template file.`

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hey there!

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. ??

    Regards,

    Thread Starter ninsan

    (@jennyrigsjo)

    Hello @aswingiri and @missveronicatv

    I apologize for not getting back to you sooner as I have been away on holiday. I just wanted to thank you for taking the time to try to help me and to let you know that I found a solution to my problem. I’m posting it here in case anyone else runs into the same issue:

    To change the default location of custom templates intended to override default/builtin profile templates (e.g. profile/posts-single.php), you need to place the following code in a mu-file or your theme’s functions.php file:

    add_filter('um_get_template', 'my_um_custom_templates_location', 10, 4);
    
    function my_um_custom_templates_location($located, $template_name, $path, $t_args) {
    
        if ($template_name === 'profile/posts-single.php') {
            // Note that dirname(__FILE__) returns the absolute path to the directory of 
            // the currently running script
            $located = dirname( __FILE__ ) . '/ultimate-member/templates/profile/posts-single.php';
        }
    
        return $located;
    }

    To specify the path to a custom template that is NOT intended to override any of the builtin/default profile templates, you need to include() the path to the template file inside a function, then add this function as a callback to the ‘um_profile_content_{$nav}‘ filter hook. For instance, I have a custom post type ‘text’ that I want to display in a custom ‘texts’ tab in users’ profiles:

    add_action('um_profile_content_texts', 'my_um_profile_content_texts');
    
    function my_um_profile_content_texts($args) {
    
        // define text args
        $text_args = array(
            'author' => um_profile_id(),
            'post_type' => 'text',
            'post_status' => 'publish',
            'numberposts' => -1, //all texts
        );
    
        // get the texts
        $texts = get_posts($text_args);
    
        if (!empty($texts)) {
            foreach ($texts as $text) {
                include(dirname(__FILE__) . '/ultimate-member/templates/profile/texts-single.php');
            }
        }
    }

    For instructions on how to create/add custom tabs in user profiles, see here: https://docs.ultimatemember.com/article/69-how-do-i-add-my-extra-tabs-to-user-profiles

    /jenny

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @jennyrigsjo

    Thanks for sharing the solution. Much appreciated.

    Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change custom templates location?’ is closed to new replies.