• Hi,

    I am a php and wp rookie. I appreciate any help !

    1) I want to remove featured post image and all its thmubnails (on single post, main page, just remove it completely) if the size of the image is smaller than (criteria: dimensions or KB, whatever).

    How to modify this code in the function.php ?

    add_action('do_meta_boxes', 'change_image_box');
    function change_image_box()
    {
    	remove_meta_box( 'postimagediv', 'post', 'side' );
    }

    2) It would be perfect to add a default image for the removed small featured images.

    Please help
    @gorakhsth

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi ,
    Please add the following code in the functions.php file:

    <?php
    function modify_post_thumbnail_html($html, $post_id, $post_thumbnail_id, $size, $attr) {
        $id = get_post_thumbnail_id(); // gets the id of the current post_thumbnail (in the loop)
        $src = wp_get_attachment_image_src($id, $size); // gets the image url specific to the passed in size (aka. custom image size)
        $alt = get_the_title($id); // gets the post thumbnail title
        $class = $attr['class']; // gets classes passed to the post thumbnail, defined here for easier function access
    
        // Check to see if a 'retina' class exists in the array when calling "the_post_thumbnail()", if so output different <img/> html
        if (strpos($class, 'retina') !== false) {
            $html = '<img src="" alt="" data-src="' . $src[0] . '" data-alt="' . $alt . '" class="' . $class . '" />';
        } else {
            $html = '<img src="' . $src[0] . '" alt="' . $alt . '" class="' . $class . '" />';
        }
    
        return $html;
    }
    add_filter('post_thumbnail_html', 'modify_post_thumbnail_html', 99, 5);
    ?>

    You can change anything in this code.

    Thanks!

    Thread Starter wordpresslover7

    (@wordpresslover7)

    Wow! Thanks a lot @shobhit2412 !

    I would be grateful for a bit more clarification.

    Is ‘retina’ class are those small images I want to remove from the post thumbnails? This tends to be a “copy paste” solution ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Remove featured post image if size is smaller than..’ is closed to new replies.