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

How to skip the creation of landscape thumbnails for an original portrait image

You were headed in the right direction. There is another filter out there that handles intermediate_image_sizes_advanced. You can add or remove custom sized thumbnails in there. Rather than NOT creating your landscape custom sizes on a Portrait upload, maybe try to only create the landscape custom sizes on a landscape upload. add_filter( ‘intermediate_image_sizes_advanced’, function( $sizes, … Read more

How to create interactive charts on WordPress?

It is possible to create interactive charts on a WordPress site. This will require custom code on your end to accomplish, but several JavaScript libraries exist that can help facilitate this. I have created custom charts using javascript libraries such as D3.js. Here is a great resource to get you started: https://getflywheel.com/layout/how-to-add-charts-to-your-wordpress-site-using-d3-js/.

get_post_gallery with Gutenberg

Using birgire’s suggestions, I came up with the following solution that is working well with both the old pre-WP 4.x data and the newer posts that have been added under 5.0. // if there is a gallery block do this if (has_block(‘gallery’, $post->post_content)) { $post_blocks = parse_blocks($post->post_content); $ids = $post_blocks[0][attrs][ids]; } // if there is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)