Dynamic sets galleries based on user needs


I was thinking having options on backend. Which ACF plugin can do... just wanted to have something that doesn't rely on plugins. I have page template that pulls in recent post in a grid format but having the flexible backend would be useful.


How do I insert caption, alt and title in every image in the gallery Thank you


I thought about using wp_get_attachment_image() function, which return 'alt', and 'title'. It also returns 'src' and 'class'.

You should add this attributes to images in WP admin panel.


Hi Walter,

Here is an example to build an array of WordPress attachment data:

$attachment = get_post( get_post_thumbnail_id() );
$data = array(
  'id'          => $attachment->ID,
 'title'       => $attachment->post_title,
 'name'        => $attachment->post_name,
  'caption'     => $attachment->post_excerpt,
 'alt'         => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
  'description' => $attachment->post_content,
 'url'         => wp_get_attachment_url( $attachment->ID ),
  'link'        => get_attachment_link( $attachment->ID ),
);

This should contain all the data your are after, let me know if it doesn't and I will happily modify it to fit your needs 😉

Happy coding,


Thanks for making this sweet snippet, Mariusz.

I'm still pretty new in Beans framework. May I know how I can extend this snippet like adding a video to the gallery?

Hope someone could help me out.

Thanks, Jive


@Jive I think it's not possible, because my snippet uses image field type. Beans supports only a few of them:

Text, Textarea, Select, Checkbox, Radio, Image, Slider, Group

http://www.getbeans.io/documentation/field-types/

In this case multiple images.

If you want you can use Text field instead to get movie url and maybe some placeholder image. But there will be only one movie. To get multiple text field you should nest code with another for loop and add some logic.

  • 1
  • 2

Write a reply

Login or register to write a reply, it's free!