A
A
ak_wi2018-01-27 18:07:16
WordPress
ak_wi, 2018-01-27 18:07:16

How to determine if the image being created in Wordpress post is a thumbnail?

function add_attachment_filter($post_id) {
  $att_post = get_post($post_id);
  if($att_post->post_type == 'attachment' && isset($att_post->post_parent)) {
    $parent_post = get_post($att_post->post_parent);
    if ($parent_post->post_type == 'project') {
      add_filter('intermediate_image_sizes_advanced', 'add_image_insert_override',  10, 2 );
    }
  }
  return $post_id;
}
add_filter( 'add_attachment', 'add_attachment_filter' );

There is such a function that is called when I upload an image to a specific post. If the post type is project, I call a filter that removes the creation of unnecessary image thumbnails (saving space). How to check if the generated image is a post thumbnail for a post?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question