I am trying to make things work like where any post attachment image will generate embed code automatically.
Example: If I upload and add two images 1. 250×150 2. 600 x 160 and insert into post. Now that image information I want to auto put into embed code like below.
<div>
<a href="link url" title="title text" target="_blank"><img src="$image_url" width="$image_width" height="$image_height" alt="$image_name" /></a>
</div>
where $variable is the data of the attached image/s.
So above code our team member can use the embed code to display image.
WordPress has a predefined function,
wp_get_attachment_image_src
that returns the following information as an array:But, the function requires that you know the attachment’s ID, not the post’s ID. In order to get that, you’ll need to use
get_post_thumbnail_id
.Here’s the two functions together in action:
After that, you can easily do what you’re talking about in your question.
If you want more information about the wp_get_attachment_image_src, you can read more about it here: http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src.