How to add element to the list of adjacent images?

There’s a few problems here. Your regex is pretty broken. You should be using a tool like regex101 to test that. I think for your first function you need to add the possibility of newlines between the image tags like so: /(<img.*?>\r?\n?){2,}/ You can add * before the ?‘s if you want to grab multiple … Read more

How to get featured image of last post in a category?

Correct this line in your code at the end of function. echo get_the_post_thumbnail($page->ID, ‘thumbnail’); should be echo get_the_post_thumbnail($post_id, ‘thumbnail’); also as per WordPress documentation, category_name parameter should be a string representing category slug, not name. So, the complete code should look like this: $arg = array( ‘orderby’ => ‘date’, ‘number’ => 10, ); $categories = … Read more

How to trigger “wp_handle_upload_prefilter” filter when uploading an image programatically?

I eventually got this. Solution was to use wp_handle_upload() function. Kinda obvious, when I come to think about it… function handle_upload( string $path ): array { $filename = basename( $path ); $random_filename = rand( 0, 1000 ) . $filename; $tmp_path = str_replace( $filename, $random_filename, $path ); /** Create a temporary copy of the original file, … Read more

Image sizes reset when changing theme

When you upload an image using Media Uploader, WordPress generates various image sizes(different copies) for the picture that you upload. Go to media and find whether there are multiple images with different sizes. I guess switching themes is not a reason for changing image sizes. Refer this link, it may help you

Images 404 after wp migration to a subdomain

Image URLs are stored within the ‘post’ entry that is the media item. So you can change each one manually via the Media screen. Or use a search/replace plugin to do it all at once. I like the “Better Search and Replace” plugin. Just enter the old URL’s domain, and the new one. Use the … Read more