• In WordPress 2.9 there’s a new function for adding a thumbnail (or larger) image to a post. If you put the_post_image() in your themes, it will print out the <img> associated with a given post. It’s pretty great!

    Before this function, I was using custom fields to add thumbnails to posts. The way it worked was that I would just put the URL to the image in a custom field. Because the custom field had the URL alone, I could use this in CSS as well as in PHP/HTML. I found this quite useful.

    So while the new function is great for outputting an img, I would like to have an additional function that would just output the img’s src. I think it could be the_post_image_url(). I looked at the wordpress source code, but I don’t have the expertise to write this function. Does anyone have some good ideas on how to start?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Justin Tadlock has a good writeup about the new feature. Probably what your wanting to do can be done with a filter which is explained in his post.

    http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature

    Thread Starter apatheticresistance

    (@apatheticresistance)

    Thanks Jeremy. Yeah, I saw that writeup, but maybe you or someone else can help me with one part of the implementation.

    From the tutorials I’ve found, it’s easy to use filters to add markup around something that wordpress is already outputting. For instance, if I want to make the post image permalinked to the post, I can create a filter that will wrap the <img> in an <a>.

    So it seems easy to add markup with filters. But can we strip away markup with filters?

    Justin’s filter example wraps the $html variable that the_post_image() uses in an <a>. But how can we take the $html, see what’s inside of that, and extract just the URL? Can filters actually do that?

    Thanks for the help!
    Trevor

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘how to create the_post_image_url()’ is closed to new replies.