Use bellow filter in the functions.php
<?php
add_filter( 'upload_dir', function($args) {
if( !isset($_REQUEST['post_id']) ) {
return $args;
}
$post_type_name = get_post_type( $_REQUEST['post_id'] );
if( $post_type_name="custom_post_type" ) {
// Set the new path depends on current post_type
$newdir="https://wordpress.stackexchange.com/" . $post_type_name;
$args['path'] = str_replace( $args['subdir'], '', $args['path'] ); //remove default subdir
$args['url'] = str_replace( $args['subdir'], '', $args['url'] );
$args['subdir'] = $newdir;
$args['path'] .= $newdir;
$args['url'] .= $newdir;
return $args;
}
return $args;
} ); ?>
https://gist.github.com/mostafasoufi/c525572d9b4404808b0a7bbf14f09ffa
Related Posts:
- Using Image Sizes for Custom Post Types outside the Loop
- add_image_size() for specific Post Types
- Creating an Image-Centric Custom Post Type?
- How to disable generation of default image sizes for some custom post types?
- Why does my custom WP role need edit_posts to edit images?
- List most recent image uploads, but only for specific custom post type
- set_post_thumbnail_size in percent, not pixels?
- How to add a CSS class to every image in a Custom Post Type
- Custom post type Admin Page
- Extract image src from a post and send it to an external form
- Removing Image Sizes for Custom Post Type
- Image size filtering in Media uploader according to custom post type
- Count all images of a certain post type
- How to get source of custom meta image?
- Stopping WordPress from Auto Generating Image Files for Sizes
- How can i place Feature Image under title field in wp-admin?
- Uploaded image not appearing in custom post type
- Thumbnails on next/previous links in custom post type single.php
- Return Attachments from Custom Post Type
- How to get category image custom post type taxonomy in wordpress?
- add_image_size for post type
- Set Custom Image Size Just For Specific Custom Post Type
- Issue to get wp_get_attachment_image with cmb2
- How to rename image at uploading on specific plugin or post-type in WordPress
- How to insert multiple images into a single post within a CPT
- Adding class to featured image
- Change post featured image on hover
- Show Post Thumbnail In Custom Post From Other CPT
- List all images from a single post meta value
- Custom Image Thumbnails of Different Sizes
- Featured Images does not show in custom post type
- uploading images to specified directories
- Get image post ID in media upload
- Link to full size post thumbnail
- Hide editor while keeping add media button in custom post type
- Custom Post Type with image gallery
- Multiple featured sizes / images / excerpts
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- How to Create an Image Upload Box for Custom Posts?
- Custom Post Type And “fopen”
- Add custom image size for custom post type or taxonomy
- How to automatically set ‘default image size’ for specific Custom Post Type
- Problem: wp_query outputs all images on site
- Problems with image size on the server WordPress
- frontend image post uploader
- Adding custom image sizes and post types to a plugin or to a theme?
- How to handle large number of images in a post?
- How do you get the full size url of an attachment image
- How to add multiple images to a custom post type without plugin [closed]
- how to post default thumbnail if post not created yet
- get_the_post_thumbnail_url(‘full’) returns empty from custom post type
- How can i link a custom post type thumbnail to intermediate size
- Is it possible to add posts and images (auto resize) for custom post types with a script?
- How do you output an unknown number of images in a custom post type with desired markup?
- copy images from custom field to another custom field
- link featured image to external link
- Cannot upload featured image to a custom post type
- Thumbnails Not Generating
- Should i use custom post type for a custom footer?
- Returning an image url from its attachment ID using a custom post type plugin
- Images not load on custom post type sidebar, related posts
- Not Able to Add New Class To CPT Attachment Image
- How to add Support to show Fullwidth Featured Image of Custom Post Types in WordPress.?
- DIVI Theme customizer changes not applied on existing pages and designs are not shown on the front
- How can I add image sizes for a specific custom post type?
- Change picture attachment meta of all occurrences of a picture
- Dupplication of Custom Post Type while adding attachment
- Media is not showing on post page
- In the admin, how can you list thumbnails instead of titles for a custom post type?
- Looping through image object using ACF and CPT UI [SOLVED]
- Multi Photo Upload with Caption on Front End for Custom Post Type
- Displaying image instead of post label in wordpress
- Links Image in “Catalog” Page to Posts
- How do I set a specific size for my image?
- Trying to get custom post type attachment images to function in indexed array
- Working with gallery shortcode and get gallery images
- Image paths on custom post types getting /post_type/ added to path
- Retrieve post data via WPDB class
- How to Create a Frontend Html-list Editable in the Backend?
- Allow authors to create article image
- Add Image field to CPT
- img src not working correctly in custom post type
- Add a background image into a post [closed]
- Front end post or photo or both
- Using wp_insert_post to create custom posts with ACF image field
- set_post_thumbnail or media_sideload_image adds image multiple times in media library
- How to Create Grey Background for Product Images on Website Display but Retain White Background on Downloaded JPGs?
- is using “require_once” in wordpress theme affect the speed ???
- Custom taxonomy with custom post type template not showing
- Delete Post by User
- Issue with Custom Post Types and Permalinks
- Can I show some specific post rather than latest post?
- Support for author does not show author column in post table in dashboard
- Loop to display parent categories in custom taxonomy
- Adding admin menu seperators around CPT’s
- Getting Custom Posts with Custom Taxonomy
- CPT remove /blog/ by add new portfolio default /blog/%postname%/
- Use Category for Custom Post Type – But Need Another Separate Archive Page too
- Use WP Title instead of custom field to call
- Add an array as post content dynamically