If you want to change the post thumbnail URL, use the filter wp_get_attachment_url
;
Try to follow the next code:
// NAV: Change the url for thumbnail for post
function wpcoder_change_post_thumbnail_url($url, $post_id) {
if (strpos($url, 'img/uploads/') !== false) {
$year = date('Y'); // Year folder
$month = date('m'); // Month folder
$url = str_replace("img/uploads/", "app/uploads/'.$year."https://wordpress.stackexchange.com/".$month.'/", $url);
}
return $url;
}
add_filter('wp_get_attachment_url', 'wpcoder_change_post_thumbnail_url', 10, 2);
This filter allows you to modify the URL of an attachment (thumbnail) based on conditions you define. In the example, it checks if the URL contains ‘img/uploads/’ and replaces it with your custom URL.
You can add the code in the file ‘functions.php’ or add using the free plugin WP Coder via page Global PHP
Related Posts:
- Programmatically get images by URL and save in uploads folder
- How to find attachment by it’s name?
- Insert an image into a post by API
- Programatically creating image attachments from local URLs and setting featured image
- Show prev and next post links for parent post of current image in attachment page?
- How do you import images from a URL in your post?
- Retrieve Image Attachments Getting Post Thumbnail Image First
- Custom image size not displaying with wp_get_attachment_image()
- How to echo images Urls from a wordpress post, that are relally in the post
- attachment_fields_to_save first parameter is null
- Troubles with code for upload a image
- How can I use an image from an external source without uploading it to the media library
- How to get image title/alt attribute?
- Get the first image from post content (eg.: hotlinked images)
- Download an image from a webpage to the default uploads folder
- wp_get_attachment_image_src and server path
- Change WordPress image URLs via filter
- get_the_post_thumbnail_url with an unregistered size
- Any easy way to automatically set the first inline image in a post as the thumbnail?
- How can I hide media library images from general users?
- Associate an existing image with a post
- set_post_thumbnail_size not cropping featured images, but reducing proportionally
- How do i upload an image and return the image id?
- Get Attachment ID from URL [duplicate]
- How to change _wp_attachment_metadata specific value in SQL?
- Is it possible to prevent users from uploading small images?
- Can’t Display Featured Image in RSS Feed
- How to upload image without post ID using the new media uploader?
- Applying class to links around self hosted images embedded to posts/pages
- Featured Images on Front Page
- Pulling Post Image Attachments in WordPress 3.9
- Setup A Default Featured Image
- Find posts without featured image? [duplicate]
- How do I add a featured image to a single post page?
- Link Featured Thumb to Attachment Page, If Possible
- Image still linked as attachment to page even though it has been deleted
- Disable wordpress image sizes generation
- Featured Image .svg height and width 1px only
- Images are randomly deleted from server
- Frontend Post – Allow Only Image File Upload
- Add a new data attribute in tag
- Images not working using Featured post
- Add instructions to featured image
- How do I get more image editing options in the admin?
- Woocommerce featured image of page – not product
- Can’t seem to attach uploaded image to post and set it as thumbnail
- Add an attribute to attachments
- Store Snapshot created via wordpress to use with lightbox
- How to stop thumbnail generation from some images and different size thumbnail generate
- Custom Loop, Match Category with Page: How to display post featured image?
- Does wp_get_attachment_image_src also work with non-image files?
- How do I get my main image to stretch the full length of the screen?
- wp get attachment image always gives me thumbnail
- Filter for post_thumbnail: link to small src and add data-attribute [duplicate]
- How to display original unmodified thumbnail
- How to hide image-url if no attachment?
- How to set featured image from external url programmatically
- Hide Featured Image box – isn’t working?
- Remove Additional image sizes created by theme
- WordPress Attachments with old images
- Set two default featured images
- What is the best way to associate multiple images to one page?
- How to get the cropped image from media library?
- Random Characters in the end of every image url in post
- resize and crop thumbnail photos
- Can i have 2 separate Galleries on 2 separate pages each go to a DIFFERENT Attachment.php file?
- Attachments without images
- How to only show div of caption if caption exists on featured image
- How to use default image as featured image by implement some code in function.php
- WordPress Multisite: Images moved to /sites/1?
- wp_insert_attachment() dupplicate attachment posts
- WordPress Responsive Image ( srcset ) not work properly
- How to Display Image Caption but Not Alt Text
- Image alt attribute
- I cannot upload images to post or the media library in wordpress
- Images missing from Blog post page
- Why image Thumbnail url is not displaying with custom size?
- How to disable post-thumbnail from generation?
- Why does wp_get_attachment_image_src return the wrong size, when the correct size exists?
- second featured post not displaying on page [closed]
- set_post_thumbnail_size only working for width
- Newly uploaded images are not updating in featured image
- Extract url from next_image_link
- Lots of attachments is causing slow load
- How do I get resized thumbnails?
- Making a thumbnail if there exist a link with. jpg or .png extension in WordPress
- Why is WordPress loading a different sized post thumbnail?
- Create post thumbnails from images stored outside of uploads directory
- Title image is missing ( but is not the WP 3.5 issue )
- Images will not attach to posts after site migration
- How to access & display images from a post without textual content ( and vice versa) according to best wordpress practices
- Using the on-board image editor for featured images: edits are not being used
- Tried everything but Facebook share button won’t load the post thumbnail
- has_post_thumbnail() Returns False on Scheduled Posts
- How can we see which posts don’t have a featured image or it doesn’t exist anymore?
- Why some images are not allowed to be edited only for thumbnails?
- How to import external media items into wordpress media library (without using storage)
- Is there a way to upscale a media library original image to the nearest whole pixel in WordPress?
- Get field added via attachment_fields_to_edit filter in Gutenberg
- How to get rid of a blank space where the featured image used to be?