Question

I'm attempting to make use of an image uploader, and I have it working in normal posts. However, it does not work on custom post types.

After some searching, it seems I need to call wp_enqueue_media(); somewhere, however, if I do then neither normal posts nor custom post type image uploaders work.

What is the best way to call this function for custom post types?

Was it helpful?

Solution

function media_uploader() {
    global $post_type;
    if( 'custom-post-type' == $post_type) {
        if(function_exists('wp_enqueue_media')) {
            wp_enqueue_media();
        }
        else {
            wp_enqueue_script('media-upload');
            wp_enqueue_script('thickbox');
            wp_enqueue_style('thickbox');
        }
    }
}
add_action('admin_enqueue_scripts', 'media_uploader');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top