Get the post thumbnail URL in WordPress


// store post id in a variable
$post_id = get_the_ID();

//get image attributes like 'url', 'width' and 'height', of an image attachment file.
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'full' );

$url = $thumb['0']; // get url from array
print_r($thumb);

Output of above code

Array
(
    [0] => http://localhost/testword-press/wp-content/uploads/2014/26/image9.jpg
    [1] => 224
    [2] => 260
    [3] => 
)
Advertisements

2 thoughts on “Get the post thumbnail URL in WordPress”

  1. obviously like your web-site but you have to take a look at the spelling on quite a few of your posts. A number of them are rife with spelling issues and I to find it very bothersome to tell the truth on the other hand I’ll definitely come again again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s