• Recommend you change hot_random_image.php code block for file types, to include webp files.

    function randomimage_select_image( $path, $link, $width, $height, $alt ) {
    
    	$images1 = glob($path.'/*.jpg');
    	$images2 = glob($path.'/*.png');
    	$images3 = glob($path.'/*.gif');
    	$images4 = glob($path.'/*.jpeg');
    	$images5 = glob($path.'/*.svg');
    	$images6 = glob($path.'/*.JPG');
    	$images7 = glob($path.'/*.PNG');
    	$images8 = glob($path.'/*.GIF');
    	$images9 = glob($path.'/*.JPEG');
    	$images10 = glob($path.'/*.SVG');
    	$images11 = glob($path.'/*.webp'); // Add this line
    	$images12 = glob($path.'/*.WEBP'); // Add this line
    
    	$images = array();
    			
    	if(!empty($images1))
    		$images = array_merge($images,$images1);
    	if(!empty($images2))
    		$images = array_merge($images,$images2);
    	if(!empty($images3))
    		$images = array_merge($images,$images3);
    	if(!empty($images4))
    		$images = array_merge($images,$images4);
    	if(!empty($images5))
    		$images = array_merge($images,$images5);
    	if(!empty($images6))
    		$images = array_merge($images,$images6);
    	if(!empty($images7))
    		$images = array_merge($images,$images7);
    	if(!empty($images8))
    		$images = array_merge($images,$images8);
    	if(!empty($images9))
    		$images = array_merge($images,$images9);
    	if(!empty($images10))
    		$images = array_merge($images,$images10);
    	if(!empty($images11)) // Add this block
    		$images = array_merge($images,$images11);
    	if(!empty($images12)) // Add this block
    		$images = array_merge($images,$images12);
    
    	$html = '';
    
    	// clean all thumbnails
    	$pattern = '/^.+?\d{1,4}x\d{1,4}.+$/';
    	foreach ($images as $key => $value) {
    	    // Check if the value matches the pattern
    	    if (preg_match($pattern, $value)) {
    	        // If it matches, unset the element from the array
    	        unset($images[$key]);
    	    }
    	}
    	// remove empty elements from the array
    	$images = array_values($images);
    		
    	// randomly select an image
    	$ind = wp_rand(1,count($images));
    	if (isset($images[$ind - 1])) {
    		$image = $images[$ind - 1];
    	} else {
    		$image = false;
    	}
    
    	if($image){
    
    		// get image caption and alt (if image is registered in Media)
    		$image_id = attachment_url_to_postid( esc_url(get_site_url().'/'.$image) );
    		$image_caption = '';
    		$image_alt = $alt;
    		if($image_id) {
    			$image_caption = wp_get_attachment_caption( $image_id );
    			$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);
    		}
    
    		$html .= '<figure class="wp-block-image">';
    		if($link){
    			$html .= '<a href="'.esc_attr($link).'">';
    		}
    			$html .= '<img class="hot-random-image" style="width:'.esc_attr($width).'; height:'.esc_attr($height).';" src="'.esc_url(get_site_url().'/'.$image).'" alt="'.esc_attr($image_alt).'" />';
    
    		if($link){
    			$html .= '</a>';
    		}
    
    		if ($image_caption) {
    			$html .= '<figcaption>'.$image_caption.'</figcaption>';
    		}
    		
    		$html .= '</figure>';
    	}
    
    	if (!$path) {
    		return '<img class="hot-random-image" style="width:'.esc_attr($width).'; height:'.esc_attr($height).';" src="'.get_site_url().'/wp-content/plugins/hot-random-image/images/hot_random_image.png" alt="'.esc_attr($alt).'" />';
    	}
    	
    	return $html;
    
    }
    
Viewing 1 replies (of 1 total)
  • Plugin Author Hot Themes

    (@hotwptemplates)

    Hello,

    Thank you for your recommendation. The support for WEBP images is added in the version 1.9.2.

    Best regards,
    Milos

Viewing 1 replies (of 1 total)
  • The topic ‘Excellent!!!!!!!! Added Webp files’ is closed to new replies.