Conditional to grab parent page thumbnail URL

<?php $id = $post->ID; if( ! has_post_thumbnail( $id ) ) { // the current page has no feature image // so we’ll see if a) it has a parent and b) the parent has a featured image $ancestors = get_ancestors( $post->ID, ‘page’ ); $parent_id = $ancestors[0]; if( has_post_thumbnail( $parent_id ) ) { // we’ll use … Read more

Change admin post thumbnail size for custom post type only

admin_post_thumbnail_size takes three parameters: $thumb_size: selected Thumb Size if you do nothing in the filter. $thumbnail_id: Thumbnail attachment ID. $post: associated WP_Post instance So you may make use of these parameters to have a better control in your CODE. Use the CODE like below: function custom_admin_thumb_size( $thumb_size, $thumbnail_id, $post ) { if( ‘slider’ === $post->post_type … Read more

How do I programmatically add an image to a post?

Hey I used this code for something similar(I was also downloading remote image and uploading to WordPress site). Please have a look: $image_url = $value;//This is the sanitized image url. $image = pathinfo($image_url);//Extracting information into array. $image_name = $image[‘basename’]; $upload_dir = wp_upload_dir(); $image_data = file_get_contents($image_url); $unique_file_name = wp_unique_filename($upload_dir[‘path’], $image_name); $filename = basename($unique_file_name); $postarr = array( … Read more