Skip to content

Get Featured Image As URL

Eric Stout edited this page Apr 24, 2016 · 1 revision

We've now added the ability to get a featured image as a url.

function featuredURL($size){
  $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), $size );
  $url = $thumb['0'];
  echo $url;
}

This function can be found in inc/thumbnails.php

Usage

To use this function, simply call featuredURL($size) in your theme. Be sure to replace $size with the thumbnail size you want WordPress to return.

Example:

<div class="hero" style="background: url(<?php featuredURL('hero');?> center center no-repeat;">
  <h1>Hero!</h1>
</div>

Clone this wiki locally