Wednesday, 12 September 2018

How to get custom image size url in Wordpress

Here are simple way to get custom image from URL

$imgUrl = 'http://localhost/wptest/wp-content/themes/sydney/images/header.jpg';

 
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $imgUrl ));
$image_id = $attachment[0];
$thumbnail_url = wp_get_attachment_image_src($image_id, array('615','440'), true );

0 comments:

Post a Comment