Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a custom taxonomy, this taxonomy is dedicated to image attachments, when I upload my images $post->post_content returns a string like:

'[caption id="attachment_98" align="alignnone" width="300"]
  <a href="http://....jpg">
     <img class="size-medium" title="title" src="http://.../wp-content/uploads/2012/10/name.jpg" alt="cardinal2" width="300" height="225" />
  </a>
caption[/caption]'

By calling the_content() this string becomes an HTML markup, at codex I couldn't find a function that allows me to get the source of the image and caption/description/title of it in a dynamic way, is there a way to output the content without using the_content() function? Should I split the result?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Filter 'img_caption_shortcode'. You get three arguments: an empty string, the attributes (including the attachment id), and the caption content. If you return anything but an empty string WordPress will print your return value instead of its own code.

See wp-includes/media.php for details.

Another option: hijack the caption handlers and create your own output or change the output WordPress builds before it is sent back to the content.

share|improve this answer
    
Thank-you very much for your answer, does this work when I have more than 1 image in my post? is there any other way that I can return title and description of the image too? I am about to create a gallery and I want to json_encode the results. –  Raminson Oct 10 '12 at 4:02
    
See my update, especially the linked answer. –  toscho Oct 10 '12 at 4:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.