Attachment Metadata inside of Loop

Basically, I'm trying to call attachment info to display withing a loop, for use in an image gallery. I know I need to use wp_prepare_attachment_for_js($attachment_id) but I can't seem to get anything to show. Here's the HTML: <?php $the_query = new WP_Query(array( 'post_type' => 'attachment', 'post_status' => 'inherit' )); while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php attachment_meta = wp_get_attachment($id); echo '<figure class="gallery-photo" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" data-groups='["all", "'.$attachment_meta['category_name'].'"]'><a class="photo-link" href="'.wp_get_attachment_image ().'">" itemprop="contentUrl" data-size="'.$attachment_meta[width].'"x"'.$attachment_meta[height].';?>"> <img src="'.wp_get_attachment_url ('fullsize').'" itemprop="thumbnail" /> <figcaption itemprop="caption …
Category: Web

How to insert fancybox to multiple separate galleries in a post?

Okay I'm trying to add fancybox functionality to the galleries in posts. I found this stack exchange: How do i add class="fancybox" to the default gallery? and I managed to get the basic fancybox functionality using: jQuery(".gallery-icon a").fancybox().attr('rel', 'gallery'); But it's not grouping the images all in one gallery together. I can click on an image and get a lightbox but there's no scrolling through a group. I tried the solution outlined by @orionrush jQuery('.gallery').each(function (g) { jQuery('a', this).attr('rel', function …
Category: Web

Insert wp gallery shortcode into custom textarea

Is there a way to insert wp gallery shortcode into custom metabox textarea ? I would like to have something like this: New metabox in post/page with textarea and below textarea there are a button to open wp browse media gallery lightbox. then when we have done to select few images as gallery, click the "insert gallery" button will insert the shortcode to the textarea custom field. is it possible ? Thanks ====== Update: ====== I was able to show …
Category: Web

How to change the output of gallery shortcode

I would like to add the media description as a data-attribute to each image of the gallery. All the other answers favour the solution to copy the whole code from media.php to functions.php and change it there. But isn't there a more intelligent way? It's way to much code duplication in order to change one single line of code!
Category: Web

show image gallery in archives or category page

i want to show image gallery in archives.php or category.php. The featured image and text content is showing but not image gallery. Below is the code inside category.php. I have tested to show one post from category 'blog'. $args = array( 'post_type' => 'post', 'post_status' => 'any', 'cat'=>3, 'meta_query'=> array('relation'=>'AND', array( 'key'=>'intro_post','value'=>'intro','type'=>'CHAR','compare'=>'LIKE' ) ) ); $arr_posts = new WP_Query( $args );?> <?php if ( $arr_posts->have_posts() ) : ?> <?php while ( $arr_posts->have_posts() ) : $arr_posts->the_post(); ?> <div class="entry-content"> <?php if …
Category: Web

offset and max_num_pages in pagination gallery

I rewrote the code galleries and stopped at the pagination. How can I get the maximum number of pages? at the moment I can not define it, and put a test for the number 5. (Here "for ($ i = 1; $ i <= 5; $ i ++)" here "if ($ paged <5))." And how to make that work offset parameter in pagination? Now when I put the parameter offset, pagination will not work correctly. I need to post 16 …
Category: Web

Delete images from media library when user deletes an image from ACF Gallery

When a user deletes an image from the gallery in wp-admin I need it to be deleted from the media library too. I have a function using the acf/update_value hook which works uncorrectly. When a user simply updates a post, WordPress removes all images from the media library and current gallery field. Please tell me how to fix it? All the old questions don't work :( add_filter('acf/update_value/type=gallery', 'remove_gallery_images', 10, 3); function remove_gallery_images($value, $post_id, $field) { $images_to_delete = array(); $old_value = …
Category: Web

Custom default settings for WP native Gallery Block

I've started with MarkJ's answer - JavaScript included into the block editor. I wanted to control more attributes for gallery than linkTo — the number of columns, cropping, and image size. wp.domReady( function() { wp.blocks.registerBlockVariation( 'core/gallery', { isDefault: true, attributes: { columns: 6, imageCrop: false, linkTo: 'media', sizeSlug: 'thumbnail', // does NOT work in WP 5.9.3 } } ); }); This snippet does the job partially. In WP editor block settings panel it looks like OK. Unfortunately, in fact the …
Category: Web

Gallery functionality in custom theme

I'm new to creating my own theme and I barely scratched the surface of this topic so far. But my end goal would be to create a "gallery like" functionality. Maybe there are some functions or prebuild things in WP that could help me out here before I do all of this from scratch. Some terms what I can google for or look in the documentation would help me out a lot. Because when I search for stuff on google …
Category: Web

Issue on Getting Images URL of the Post Gallery

I am trying to get the URL of the attached galley into the post on custom page layout called Gallery Page. I tried to use the code from Codex at This Page (get post gallery images). but I am not getting any thing on the page! Can you please let me know what I am doing wrong? <?php /** * Template Name: Gallery Page * */ if ( have_posts() ) { while ( have_posts() ) { the_post(); function pw_show_gallery_image_urls( $content …
Category: Web

Is it possible to query all posts that don't have an attachment?

I want to get a list of all posts that don't have an attachment and delete them. This question takes about getting all posts that have an attachment, but I want the reverse of it. The brute force way to do it is to get all posts and then loop through them individually and then check if they have attachement or not. But I want to avoid it if possible.
Category: Web

Media changes not updating posts

What happens: Write a post Create a gallery Upload a random picture Set caption to "test" Publish Post Go to Media -> Select the picture from before Set caption to "changed" and save Go back to post Check the image Image caption still shows "test" -> Should be "changed" So if I ever update the media library with proper captions, alt text and titles it looks like they will never be updated on older posts. Is this how it should …
Category: Web

Only current gallery images with get_attached_media

On my page the gallery images are cycled and I would like to show their title as a caption. Since get_post_gallery_images only retrieves the thumbnail-url of the gallery images I have tried to use get_attached_media('image', $post); instead. The following code gives me the url and the title of the gallery images: foreach($images as $image) { $titleArr[] = $image->post_title; $urlArr[] = wp_get_attachment_url($image->ID); } However, get_attached_media('image', $post); returns all images that have ever been attached to this post, even if they are …
Category: Web

WordPress Block Variation for Gallery Columns

I had this code to extend the column count to 10 for a specific need. wp.blocks.registerBlockVariation('core/gallery', { name: 'prefix-gallery', title: 'Custom Gallery', attributes: { columns: 10, }, isDefault: true, }); But that doesn't seem to work any longer. I see the updated Block Gallery attributes has this: attributes: { { columns: { "type": "number", "minimum": 1, "maximum": 10, }, }, } So I tried: wp.blocks.registerBlockVariation('core/gallery', { name: 'prefix-gallery', title: 'Custom Gallery', attributes: { columns: { minimum: 1, maximum: 10, }, …
Category: Web

Wordpress Gutenberg custom block

I try made custom block in wordpress gutenberg. I need create block like gallery but on output i need other html structur. I write this code var el = wp.element.createElement; wp.blocks.registerBlockType('zlapchwile-gutenberg/custom-gallery-block', { title: 'Custom gallery', // Block name visible to user icon: 'images-alt2', // Toolbar icon can be either using WP Dashicons or custom SVG category: 'media', // Under which category the block would appear attributes: { imgURL:{ type: 'string', source: 'attribute', attribute: 'src', selector: 'img' }, imgID:{ type: 'number' …
Category: Web

Remove Captions from Custom Gallery function.php

I like to prevent captions from being outputted in my custom gallery function. I could easily just hide it using CSS but it doesn't feel right. The caption is being sent from media.php this line. if ( $captiontag && trim($attachment->post_excerpt) ) { $output .= " <{$captiontag} class='wp-caption-text gallery-caption'> " . wptexturize($attachment->post_excerpt) . " </{$captiontag}>"; } I could just remove . wptexturize($attachment->post_excerpt) . but as soon as I update its gone. Id like to to this without copying the whole gallery …
Category: Web

Add anchor tag on previous_image_link / next_image_link

I am using big headers on my website.I need the next/previous_image_link to target to the picture , not the top of the page. Is it possible to add anchor or to set the target on next/previous_image_link? or any other method to go to specific position on page. I found on my image.php: <div class="next l mb"><i><?php echo previous_image_link('','Previous Image') ?> </i></div> </i></div>
Category: Web

Pagination with WordPress default gallery?

Here is the part of code handling pagination in functions.php: // Pagination Setup $current = (get_query_var('paged')) ? get_query_var( 'paged' ) : 1; $per_page = 3; $offset = ($current-1) * $per_page; $big = 999999999; $total = sizeof($attachments); $total_pages = round($total/$per_page); if( $total_pages < ( $total/$per_page ) ){ $total_pages = $total_pages+1; } // Pagination output $output .= paginate_links( array( 'base' => str_replace($big,'%#%',esc_url(get_pagenum_link($big))), 'format' => '?paged=%#%', 'current' => $current, 'total' => $total_pages, 'prev_text' => __('«'), 'next_text' => __('»') ) ); Here is the …
Category: Web

ACF Gallery with Media Categories - how do display categories and sort

I would like to use something to filter images within an ACF Gallery. I have added the Enhanced Media Gallery Plugin which will allow me to assign a category to each image, but am not not clear on how to echo out that category list so it can be clicked and filter/display images in the category chosen. Additionally, how would I echo the category assigned to the image in the div surrounding the image My loop currently looks like this …
Category: Web

How can i showcase all my galleries?

i am working on a Website for News. Some Articles will have Galleries and some not. I want to have a site where one can see all of my Galleries and if clicked all Images are presented with and a linkt to the article. How would i do this? Thanks!
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.