Title: Using Post Thumbnails in a function
Last modified: August 20, 2016

---

# Using Post Thumbnails in a function

 *  [Sterling](https://wordpress.org/support/users/ster/)
 * (@ster)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/using-post-thumbnails-in-a-function/)
 * Hi everyone,
 * I was hoping someone could help me out. I’m learning javascript and wrote a script
   that changes the resolution size of a post thumbnail relative to the width of
   the browser but I am having trouble wrapping it in a function. I’m using the 
   twenty eleven theme and it works fine wherever I cut and paste it but if I try
   to wrap it in a function the function call returns nothing. i’m assuming I’m 
   doing everything wrong and that my in-line code is held together by fairy dust.
 * I need a good example of how to write a function that finds a posts post_thumbnail
   and returns the appropriate image in or out of the loop. Help or anything that
   could point me in the right direction would be greatly appreciated.
 * The concept:
    I’m making a site with a fluid layout and my goal is to be able
   to resize my images to fit accordingly but at the same time be bandwidth wise.
   I don’t want to serve a 1500px wide image to a 320px wide phone. (Its an art 
   portfolio site so its really image heavy.) For fixed images I can do this easily
   with css and media queries but for the embedded stuff I need a javascript solution.
   Post thumbnails seamed like a good way do this since they already generate several
   custom sizes. I’m by no means a coder but after a few late nights was able to
   get a proof of concept working, but it is by no means pretty and as i mentioned
   before only works in-line.
 * What is the proper way to do something like this?
 * Here is my humble little script: [http://pastebin.com/RWWTqWJZ](http://pastebin.com/RWWTqWJZ)
 * thank you,
 * Ster

The topic ‘Using Post Thumbnails in a function’ is closed to new replies.

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [post_thumbnail](https://wordpress.org/support/topic-tag/post_thumbnail/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [Sterling](https://wordpress.org/support/users/ster/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/using-post-thumbnails-in-a-function/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
