# PHP echo in dynamic data (image\_desciption)

**URL:** <https://forum.bricksbuilder.io/t/php-echo-in-dynamic-data-image-desciption/8495>\
**Category:** How To\
**Created:** [December 7, 2022, 9:20am UTC](https://forum.bricksbuilder.io/t/php-echo-in-dynamic-data-image-desciption/8495 "2022-12-07T09:20:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/michael/32/101_2.png) [@Michael](https://forum.bricksbuilder.io/u/Michael)\
**Post date:** [December 7, 2022, 9:20am UTC](https://forum.bricksbuilder.io/t/php-echo-in-dynamic-data-image-desciption/8495/1 "2022-12-07T09:20:06Z")

</div>

Hi all,

Hoping someone with more PHP knowledge can help me echo an image description:

Using images in a query loop, I am using a text element with dynamic data ‘output PHP function’.

The function is a WP function of $image\_description

I have tried many different ways but cannot seem to get it to output, variations I have tried include:

- {echo:$image\_description}
- {echo:image\_description}
- {echo:$image\_description (‘’)}
- {echo:get\_field($image\_description)}
- {echo:get\_image\_id($image\_description)}
- {echo:returnValues($image\_description)}

And many other combinations too! 😅

Anyone know where I have messed up? haha

Many thanks

Mick

---

<div class="post-metadata">

**Author:** ![rjaureg](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/rjaureg/32/4600_2.png) [@rjaureg](https://forum.bricksbuilder.io/u/rjaureg)\
**Post date:** [December 7, 2022, 10:43am UTC](https://forum.bricksbuilder.io/t/php-echo-in-dynamic-data-image-desciption/8495/2 "2022-12-07T10:43:50Z")

</div>

The WordPress function is wp\_get\_attachement\_caption

> **[wp\_get\_attachment\_caption() | Function | WordPress Developer Resources](https://developer.wordpress.org/reference/functions/wp_get_attachment_caption/)**
>
> Retrieves the caption for an attachment.

You can try \* {echo:wp\_get\_attachement\_caption} maybe you don´t need to pass post ID if you are inside the post itself.

Hope this can help you

---

<div class="post-metadata">

**Author:** ![Michael](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/michael/32/101_2.png) [@Michael](https://forum.bricksbuilder.io/u/Michael)\
**Post date:** [December 7, 2022, 12:02pm UTC](https://forum.bricksbuilder.io/t/php-echo-in-dynamic-data-image-desciption/8495/3 "2022-12-07T12:02:14Z")

</div>

Hi @rjaureg

Many thanks for the reply, but no luck, unfortunately. Again I am not overly sure if that function is for the caption and not the description, but I did try a couple of different variations of it just incase:

{echo:wp\_get\_attachment\_caption}  
{echo:wp\_get\_attachment\_caption($image\_description)}  
{echo:wp\_get\_attachement\_caption(image\_description)}

But still no joy!

---

<div class="post-metadata">

**Author:** ![rjaureg](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/rjaureg/32/4600_2.png) [@rjaureg](https://forum.bricksbuilder.io/u/rjaureg)\
**Post date:** [December 7, 2022, 2:25pm UTC](https://forum.bricksbuilder.io/t/php-echo-in-dynamic-data-image-desciption/8495/4 "2022-12-07T14:25:41Z")

</div>

Wordpress has this function wp\_get\_attachment\_image( $id ) but it returns an array so cannot be used as you want to get the description.

You should use this code for that

```auto

   $attachment_meta = wp_get_attachment_images['attachment_id']);
   echo $attachment_meta['description']; 

```

On the other side, $image\_description is a variable that you are using on your site?

The way Bricks buider use output function is like this:

> **[Dynamic Data](https://academy.bricksbuilder.io/article/dynamic-data/#advanced)**
>
> Use dynamic data to render all sorts of data from your WordPress database with Bricks. For example: Featured image, post title, post date, author name, categories, tags, site title, all of your custom fields, etc. You’ll most likely use dynamic data...

It accepts arguments, with or without single quotes, like so:  
{echo:get\_the\_date(‘Y-m-d’, 55)}`

This echoes the date of the post 55 formatted to `Y-m-d’

But I don´t know how to pass a variable which whould be a very useful thing,

Maybe someone can help with this, sorry …
