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