20 votes
Accepted

How to extend the gallery block in Gutenberg?

Ok, I've been playing with this for a little bit and have managed to change the output of the Gallery block, with the following caveats: The preview does not match the output. I think this is ...
Jacob Peattie's user avatar
16 votes
Accepted

Validation error: Extending Gutenberg gallery block

Answering my own question: As suggested by WebElaine I created a completely new block to fix the problem. To make this task easier, I used create-guten-block by Ahmad Awais, which is pretty easy to ...
Andreas's user avatar
  • 331
6 votes
Accepted

How to get ID of images used in gallery?

Are you writing a template? A filter in functions.php or a plugin? A straightforward method could be using get_post_gallery with the second argument set to false, so that it return the object rather ...
Luis Sanz's user avatar
  • 756
5 votes

Overide Gallery Default Link to Settings

Tomas's answer actually contain's the key to change default linking (for Gutenberg). Does not affect already created galleries. The best way how I was able to implement it, was creating a new edited ...
MarkJ's user avatar
  • 63
5 votes
Accepted

get_post_gallery with Gutenberg

Using birgire's suggestions, I came up with the following solution that is working well with both the old pre-WP 4.x data and the newer posts that have been added under 5.0. // if there is a gallery ...
kosher's user avatar
  • 260
4 votes
Accepted

Gallery Shortcode Showing IDs

Remove: $content = get_the_content(); and replace: <p><?php echo $content; ?></p> with: <?php the_content(); ?> See this note on the Codex page for get_the_content(): ...
Milo's user avatar
  • 78.5k
4 votes
Accepted

How I can get image description/title/alt for gallery image?

You need to get the metadata of each image, add this to your functions.php file: function get_post_gallery_images_with_info($postvar = NULL) { if(!isset($postvar)){ global $post; $...
David Lee's user avatar
  • 3,861
4 votes
Accepted

Add data attribute to a gallery link?

This solution will add the data-fancybox="group" to gallery links produced by the default [gallery] shortcode. This has been tested and works regardless of whether themes have HTML5 theme support ...
Dave Romsey's user avatar
  • 17.7k
4 votes
Accepted

Wordpress automatically adds links to uploaded images

You adjust that when you insert the image into the post, not when you upload it. When you upload the image, you will be looking at it on the Media Library page. On the right hand side is a column ...
Otto's user avatar
  • 32.6k
4 votes

get_post_gallery with Gutenberg

The get_post_gallery() is a wrapper for get_post_galleries() that has an open ticket #43826 for gallery blocks support. This is currently set to the 5.1 milestone, but it might change. You can even ...
birgire's user avatar
  • 67.1k
4 votes

How to include externally hosted images into a gallery block

What you want to do is already baked into WordPress but just not frequently used. In either the classic or the block editor, click to add an image. Once you have the block upon, instead of uploading ...
Tony Djukic's user avatar
  • 2,044
3 votes
Accepted

How to get the first image gallery of a product in woocommerce in a loop

Along with the product thumbnail (I'm assuming you have this), what you need is a list (array) of the product images - WooCommerce has such methods, eg $product->get_gallery_attachment_ids(). You ...
Isaac Lubow's user avatar
3 votes
Accepted

Gallery images titles - get from post

Gallery Image Caption - As Title Of The Post It's attached To Here's one way to do it with a custom parent_titles attribute in the native gallery shortcode. This can be achieved by setting ...
birgire's user avatar
  • 67.1k
3 votes

Split Content and Gallery

It should not be sooo complicated. The code below can be shortened down to a couple of lines at wish. Approach 1. Get the clean post content by removing all shortcodes, including the gallery one from ...
bob-12345's user avatar
  • 151
3 votes

Turn a URL into an Attachment / Post ID

Ok I found the answer that no one has on the net I been looking for days now. Keep in mine this only works if your theme or plugin is using the WP_Customize_Image_Control() if you are using ...
DevTurtle's user avatar
  • 201
3 votes

Overide Gallery Default Link to Settings

This is my working example for WordPress 5.0 (Gutenberg)! function gallery_template_to_posts() { $post_type_object = get_post_type_object( 'post' ); $post_type_object->template = array( ...
Tomas's user avatar
  • 131
3 votes

Using an Image Slider twice on the same page

My approach (take it as such) would be simply generating a unique ID which will differentiate each slider. That's anyway a good practice when the same functionality can potentially be displayed ...
ClemC's user avatar
  • 1,965
3 votes
Accepted

How do I turn a custom post type into a plugin?

Take the file the custom post type is registered in, put it in the plugins folder, and add a comment at the top, e.g.: <?php /** * Plugin Name: David A. Frenchs Custom Post Type Plugin **/ Save ...
Tom J Nowell's user avatar
  • 59.2k
3 votes

Can't get the columns of galleries when the user set the column number to 3 if there are 2 galleries?

OK, I just tested this a little further. Indeed, if you select 3 columns (the default WP gallery column count) and do a var_dump( $gallery ); you will see that there is no column key in the array. (...
LWS-Mo's user avatar
  • 1,522
3 votes
Accepted

How can I remove "<br style="clear: both">"

The default [gallery] Shortcode will add that markup when necessary and only if the active WordPress theme didn't enable HTML5 support for the gallery Shortcode's markup/output. Or, in rare cases, a ...
Sally CJ's user avatar
  • 39.1k
2 votes

Bulk edit wordpress images alt and title attributes

You can use the 'wp_get_attachment_image_attributes' hook add_filter( 'wp_get_attachment_image_attributes', 'image_attributes', 20, 2 ); function image_attributes( $attr, $attachment ) ...
Mohamed Saad's user avatar
2 votes

How do i add class="fancybox" to the default gallery?

These answer were all right but now fancybox has changed it's spec. It's no longer rel=gallery, but "data-fancybox=gallery". So the new scripts should look like this jQuery(".gallery-icon a")....
Aslan French's user avatar
2 votes

Add custom fields to wp native gallery settings

Thanks for your code. I've investigated this issue further (this is not an integer formatting problem). The only solution I came up with for number fields is to monkey patch more WP JS. Here is entire ...
jmarceli's user avatar
  • 1,066
2 votes

Modified wp.media.view.Settings.Gallery in Backbone JS, but editing doesn't work

When you save the option is it saving the custom post type to the new one which youa re assigning?. You may look into that.
Amol Bhandari SJ's user avatar
2 votes

How to draw media details for Isotope gallery using Photoswipe

I had a scenario very similar to yours. I trust these notes can help. 1 - When querying a custom taxonomy, wp_query requires a more information. The codex reference is here. The information is in ...
Tedinoz's user avatar
  • 428
2 votes

How to insert multiple images into a single post within a CPT

As I understand it, you will need create a meta box with fields and use jQuery to add/remove the image boxes. You can also use jQuery UI to make the fields draggable if you like. Your meta box code ...
user53340's user avatar
  • 103
2 votes

How to add multiple images to a custom post type without plugin

Have you tried doing something like this? I hope it will help: https://www.skyverge.com/blog/custom-post-type-with-image-uploads/
Sebastian Kaczmarek's user avatar
2 votes

How to add multiple images to a custom post type without plugin

Using custom post meta box . Visit this link
Shamsur Rahman's user avatar
2 votes

Media gallery images url instead of ID on WP API Response

This is the correct way to achieve it is this: function show_main_image($object, $field_name, $request){ $custom_fields = get_post_custom($object['id']); $main_image = $custom_fields['...
Al Rosado's user avatar
2 votes

How I can get image description/title/alt for gallery image?

The caption for an image is actually meta_data attached to the image and the get_post_gallery_images only returns a url, so in the array you won't have any other information. You could try something ...
Kyon147's user avatar
  • 121

Only top scored, non community-wiki answers of a minimum length are eligible