Enabling post thumbnails for custom post type

I’m writing a custom post type as a plugin and trying to figure out how I can enable post thumbnails within plugin documentation/template instead of enabling it in the functions.php. I tried adding the code below inside custom-post-plugin.php and it doesn’t seem to work. I still have to write the code within the functions.php to enable post thumbnails for my custom post

/ * ADD THUMBNAIL FOR POST
 * ------------------------------------------------------------------------ */
add_theme_support( 'post-thumbnails', array( 'post', 'custom-post' ) );

Sample code below

<?php
/*
Plugin Name: Example Custom Post Plugin
Description: Example post plugin for News and Press custom post
*/
?>

<?php
/* ------------------------------------------------------------------------ *
 * EXAMPLE CUSTOM POST
  ------------------------------------------------------------------------ */

function example () {

// Set UI labels for Custom Post Type
    $labels = array(
        'name'                => _x( 'Example', 'Post Type General Name', 'twentythirteen' ),
        'singular_name'       => _x( 'Example', 'Post Type Singular Name', 'twentythirteen' ),
        'menu_name'           => __( 'Example', 'twentythirteen' ),
        'parent_item_colon'   => __( 'Parent Example', 'twentythirteen' ),
        'all_items'           => __( 'All Post', 'twentythirteen' ),
        'view_item'           => __( 'View Post', 'twentythirteen' ),
        'add_new_item'        => __( 'Add New Post', 'twentythirteen' ),
        'add_new'             => __( 'Add Post', 'twentythirteen' ),
        'edit_item'           => __( 'Edit Post', 'twentythirteen' ),
        'update_item'         => __( 'Update Post', 'twentythirteen' ),
        'search_items'        => __( 'Search Post', 'twentythirteen' ),
        'not_found'           => __( 'Not Found', 'twentythirteen' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
    );

// Set other options for Custom Post Type

    $args = array(
        'label'               => __( 'Example', 'twentythirteen' ),
        'description'         => __( 'Example', 'twentythirteen' ),
        'labels'              => $labels,
        // Features this CPT supports in Post Editor
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        // You can associate this CPT with a taxonomy or custom taxonomy.
        'taxonomies'          => array('category', 'post_tag'),
        /* A hierarchical CPT is like Pages and can have
        * Parent and child items. A non-hierarchical CPT
        * is like Posts.
        */
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 4,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
    );

    // Registering your Custom Post Type
    register_post_type( 'example', $args );
}

/* Hook into the 'init' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/

add_action( 'init', 'example', 'example', 1 );

add_action( 'after_setup_theme', 'example_featured_image');
function example_featured_image() {
        add_theme_support( 'post-thumbnails', array( 'post', 'page', 'production_firm', 'example' ) );
}

Solutions Collecting From Web of "Enabling post thumbnails for custom post type"

You are most probably using add_theme_support() in the wrong context (hook).

Because you are registering the post type yourself, all you need to do is to add support for thumbnails in the supports array when you pass your your arguments to register_post_type()

supports

(array/boolean) (optional) An alias for calling add_post_type_support() directly. As of 3.5, boolean false can be passed as value instead of an array to prevent default (title and editor) behavior.

Default: title and editor

All you need to do is to pass thumbnail to the array

'supports' => ['title', 'editor', 'thumbnail'], // Add additional values as needed

You would also need to check if support for thumbnails is enabled by the theme, and if not, add post thumbnail support in your plugin.