Search
Close this search box.

WordPress: If no featured image is set, default.png is showing. How to remove default.png from rest api?

Amitpal Singh
Amitpal Singh
February 11, 2022
here’s the wp_get_attachment_image_scr function:
function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) {

    // get a thumbnail or intermediate image if there is one
    if ( $image = image_downsize($attachment_id, $size) )
        return $image;

    $src = false;

    if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
        /** This filter is documented in wp-includes/post.php */
        $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
        $src_file = $icon_dir . '/' . wp_basename($src);
        @list($width, $height) = getimagesize($src_file);
    }
    if ( $src && $width && $height )
        return array( $src, $width, $height );
    return false;
} 

as u can see if 3-rd param is true then it looks in icons dir for that image ( and i assume wp_mime_type_icon returns default.png and some of your plugins add_filter to icon_dir to be wp-includes/images/crystal

 

Just remove 3-rd parameter in your example: $thumb_url_array = wp_get_attachment_image_src($thumb_id,'full'); and it should return false if no image or image url

Share this post:

How to Attribute?

Lorem ipsum is typically a corrupted version of De finibus bonorum et malorum, a 1st-century BC text by the Roman statesman and philosopher Cicero.
for Example: Website, Social Media, Blogs, ebooks , newsletter, etc.
Lorem ipsum is typically a corrupted version of De finibus bonorum et malorum, a 1st-century BC text by the Roman statesman and philosopher Cicero.
Copied!

Got a Question? Check out our FAQ Section.

Your action, our appreciation

It encourage us to give you more valuable content on website.