2 edited body
source | link

In addition to the correct answer above, let's say you have a custom post type called "links".

WordPress automatically requests an archive called "archive-links.php". Either in your plugin or in your theme, plus the page for the single instance of an CPT entry.

<?php
// Template Logic
function cc_links_init_template_logic($original_template) {
    // Check Theme Template or Plugin Template for archive-links.php
    // some additional logic goes here^.
    $file = trailingslashit(get_template_directory()) . 'archive-links.php';

    if(is_post_type_archive('links')) {
    // some additional logic goes here^.
        if(file_exists($file)) {
            return trailingslashit(get_template_directory()).'archive-links.php';
        } else {
            return plugin_dir_path(__DIR__) . 'templates/archive-links.php';
        }
    } elseif(is_singular('links')) {
        if(file_exists(get_template_directory_uri() . '/single-links.php')) {
            return get_template_directory_uri() . '/single-links.php';
        } else {
            return plugin_dir_path(__DIR__) . 'templates/single-links.php';
        }
    }

    return $original_template;
}
add_action('template_include', 'cc_links_init_template_logic');

In addition to the correct answer above, let's say you have a custom post type called "links".

WordPress automatically requests an archive called "archive-links.php". Either in your plugin or in your theme, plus the page for the single instance of an CPT entry.

<?php
// Template Logic
function cc_links_init_template_logic($original_template) {
    // Check Theme Template or Plugin Template for archive-links.php
    // some additional logic goes here^.
    $file = trailingslashit(get_template_directory()) . 'archive-links.php';

    if(is_post_type_archive('links')) {

        if(file_exists($file)) {
            return trailingslashit(get_template_directory()).'archive-links.php';
        } else {
            return plugin_dir_path(__DIR__) . 'templates/archive-links.php';
        }
    } elseif(is_singular('links')) {
        if(file_exists(get_template_directory_uri() . '/single-links.php')) {
            return get_template_directory_uri() . '/single-links.php';
        } else {
            return plugin_dir_path(__DIR__) . 'templates/single-links.php';
        }
    }

    return $original_template;
}
add_action('template_include', 'cc_links_init_template_logic');

In addition to the correct answer above, let's say you have a custom post type called "links".

WordPress automatically requests an archive called "archive-links.php". Either in your plugin or in your theme, plus the page for the single instance of an CPT entry.

<?php
// Template Logic
function cc_links_init_template_logic($original_template) {
    // Check Theme Template or Plugin Template for archive-links.php

    $file = trailingslashit(get_template_directory()) . 'archive-links.php';

    if(is_post_type_archive('links')) {
    // some additional logic goes here^.
        if(file_exists($file)) {
            return trailingslashit(get_template_directory()).'archive-links.php';
        } else {
            return plugin_dir_path(__DIR__) . 'templates/archive-links.php';
        }
    } elseif(is_singular('links')) {
        if(file_exists(get_template_directory_uri() . '/single-links.php')) {
            return get_template_directory_uri() . '/single-links.php';
        } else {
            return plugin_dir_path(__DIR__) . 'templates/single-links.php';
        }
    }

    return $original_template;
}
add_action('template_include', 'cc_links_init_template_logic');
1
source | link

In addition to the correct answer above, let's say you have a custom post type called "links".

WordPress automatically requests an archive called "archive-links.php". Either in your plugin or in your theme, plus the page for the single instance of an CPT entry.

<?php
// Template Logic
function cc_links_init_template_logic($original_template) {
    // Check Theme Template or Plugin Template for archive-links.php
    // some additional logic goes here^.
    $file = trailingslashit(get_template_directory()) . 'archive-links.php';

    if(is_post_type_archive('links')) {

        if(file_exists($file)) {
            return trailingslashit(get_template_directory()).'archive-links.php';
        } else {
            return plugin_dir_path(__DIR__) . 'templates/archive-links.php';
        }
    } elseif(is_singular('links')) {
        if(file_exists(get_template_directory_uri() . '/single-links.php')) {
            return get_template_directory_uri() . '/single-links.php';
        } else {
            return plugin_dir_path(__DIR__) . 'templates/single-links.php';
        }
    }

    return $original_template;
}
add_action('template_include', 'cc_links_init_template_logic');