Questions tagged [attachments]

An attachment is an image or other file uploaded through the post editor's upload utility. Attachments can be displayed on their own 'page' or template. For more information, see Using Image and File Attachments.

Filter by
Sorted by
Tagged with
0 votes
1 answer
22 views

Can I redirect media urls (not attachment pages) to the post parent?

I have a really unorthodox use case, perhaps. We have a set of pdf files which our colleagues would like to track downloads for. We have been using our web server logs to get code 200 requests for ...
ImADummy's user avatar
1 vote
1 answer
48 views

How can I get all attachments by a user on a WP multisite network?

I'm creating a front-end based project where users can make posts and add images to them. It's a network of sites that users have access to. For a better user experience, I want users to be able to ...
ToongeePrime's user avatar
0 votes
0 answers
18 views

Wordpress 6.3: WPallimport not taking images from Network Media Library

Setup: Wordpress 6.3 Multisite with Woocommerce Plugins: Network Media Library and WPAllimport Network Media Library is setup to take images from Site 1. WPAllimport is activated on all multisite sub-...
user2240778's user avatar
1 vote
1 answer
66 views

wp_get_attachment_image with custom size not rendering possible 2x srcset image

I'm noticing a difference (bug?) in how WP is rendering srcset images now. If I register my image sizes with add_image_size('single_featured_image', 1280, 9999, false); add_image_size('...
James0r's user avatar
  • 91
0 votes
0 answers
9 views

How can I move the position of the View attachment page link on the Attachment Details popup in the Media Library?

I'm not trying to be lazy but I can't seem to find a hook which describes how this might be done.
jchwebdev's user avatar
  • 765
0 votes
1 answer
45 views

Get field added via attachment_fields_to_edit filter in Gutenberg

In a plugin I'm building, I've added a field named attribution to attachments via the attachment_fields_to_edit filter. I'm trying to get this info in the block editor but when I output the variable ...
leemon's user avatar
  • 1,766
0 votes
1 answer
18 views

All uploaded files using wp_mail() renamed to tmp_name

I am attempting to retain the original file name of my uploaded file using wp_handle_upload() and wp_mail(). Currently, all files are retaining their original file extension, but renaming themselves &...
user2841359's user avatar
0 votes
1 answer
25 views

How to append $metadata['sizes'] to metadata when using 'wp_generate_attachment_metadata?

When a file such as an image is uploaded, an optimized version is created with $saved = $editor->save($editor->generate_filename('name'));. This successfully writes the file to disk and the ...
Motivated's user avatar
  • 205
0 votes
0 answers
17 views

How can I get or the intermediate size of an image with wp_get_attachment_image_src without using post meta?

I'd like to get the name of an intermediate file based on it's original attachment without relying on its post meta. As the registered image sizes e.g. thumbnail have been unregistered, the post meta ...
Motivated's user avatar
  • 205
0 votes
2 answers
175 views

wp_mail attachment not working in wordpress

wp_mail attachment not working, when the form is filled with an attachment the email is sent but with no attachment received. in wp_mail documentation they said t should add something like that: $...
PC Welcome's user avatar
0 votes
1 answer
33 views

Disable Attachment Page Except for Category

I'm looking for a solution similar to here, except I want to keep attachment pages for attachments in a specific category. I tried adding the below function, but it's still redirecting all of them: ...
BlueHelmet's user avatar
0 votes
1 answer
69 views

How to add extra EXIF data when images are uploaded?

I have a function to add EXIF information to an image after the image is uploaded to a website. How do I get the EXIF information to be automatically added to the image after the image is uploaded or ...
Kelvin Ngo's user avatar
0 votes
0 answers
67 views

Parsing value from Lottie JSON file

I am creating a scrollable Lottie component in WordPress using Advanced Custom Fields. The component consists of a sticky positioned div housing the actual Lottie player and a wrapper that ...
wandervogel's user avatar
1 vote
1 answer
54 views

Display custom post type attached media file sizes

We have a custom post type slugged 'download' and it acts like a posts but with the different slug. (It displays content like a post). Now, We have a custom field named "videos" and ...
user14772091's user avatar
0 votes
0 answers
10 views

Close featured image modal windows with JS

I'm developing a plugin which let you select a fectured image for a post from an external resource e.g. an API When I select an image, I want the image select window to close. I have tried with: wp....
Alejandro Galache's user avatar
0 votes
2 answers
32 views

Media library upload hook

I would like to create a function that fires when a file is uploaded to media library to automatically assign multiple categories. So I created this code as proof of concept, but it is not assigning a ...
Lando's user avatar
  • 1
0 votes
0 answers
98 views

How to properly move media files and update data?

Bashing my head against a wall here. I want to write a function that moves the actual file of a Media Library attachment, but this must necessarily update all metadata. I am already doing a foreach on ...
Robert Andrews's user avatar
0 votes
0 answers
17 views

Using autocomplete with post_tag taxonomy on attachments

How do I use autocomplete on the post_tag taxonomy that I added to my attachments? Following the suggestion here, I added the post_tag taxonomy to my attachments: function dod_add_tags_to_attachments()...
kosher's user avatar
  • 260
1 vote
0 answers
26 views

on attachment.php, how to display previous and next attachment links that follow the same order as a custom WP Query

Current behavior I have a media page that uses a custom WP_Query to return all thumbnails of media library attachments (regardless of post parent) with a custom taxonomy of media_visibility that has ...
Mike Eng's user avatar
  • 238
1 vote
0 answers
30 views

Why not attaching images after impoting using wp cli

I want to move posts from one site to another, because of the big amount of posts I am trying with wp-cli import. The destination site also has huge amounts of posts, now when I am importing XML files....
Mi2's user avatar
  • 11
0 votes
0 answers
10 views

Attachment tag archive

I have found very useful code that creates attachment tag archive function ahub_query_attachments() { global $wp_query; { $wp_query->query_vars['post_type'] = array( 'attachment', 'page', '...
Conrad Mafer's user avatar
0 votes
0 answers
27 views

How to make attachment tag archive visible on page

I want to make my images displayed on archive by tags, but found only this code: add_action('parse_query', 'hijack_query'); function hijack_query() { global $wp_query; // When inside a custom ...
Conrad Mafer's user avatar
0 votes
1 answer
289 views

Remove one srcset entry from wp_get_attachment_image

I'm using the following code to create a fullscreen background slideshow using the Swiper JS library: <?php function background_slideshow() { $args = array( 'post_type' => '...
leemon's user avatar
  • 1,766
0 votes
1 answer
227 views

How to get Wordpress to resize images for srcset?

I've added a custom image size to my functions.php: add_image_size('banner', 1920, 300, true); I'm loading images in this custom size, using wp_get_attachment_image() to get a srcset. However ...
PWD's user avatar
  • 3
1 vote
0 answers
45 views

Give attachments an archive page, and exclude unattached ones

I am extending the use of Media/"Attachments" so that they have a custom taxonomy of "Medium" and I can display taxonomy archives on the frontend. I'd only like the archive query ...
kanga's user avatar
  • 111
0 votes
0 answers
32 views

How to add a column showing real media usage (count) to the media list view?

currently wordpress doesn't show real media usage on the media library. It shows attachments, but a media can be, for example, associated to a post via a custom field, maybe with ACF, or other ways. ...
Luca Reghellin's user avatar
0 votes
0 answers
38 views

One audio attachment, with two possible interchangeable extensions

I have multiple posts, each with an MP3 audio attachment. Now, to save some space, I want to download these attachments and convert them to OGG format, then upload them back. After converting, the ...
Yurié's user avatar
  • 1,101
0 votes
1 answer
30 views

No attachments on contact form 7

I've been using the contact form for several years now, for my current project I'm using the latest WordPress with the latest version of contact form 7, but for some reason, I'm not receiving ...
Roshan Deshapriya's user avatar
2 votes
2 answers
774 views

Bulk delete media by year

We have large media library with more than 300000 images. We decide to delete all images < 2017 year manually using "FTP", from WP upload folder. But after that in WP Admin > Media >...
Acidburns's user avatar
0 votes
1 answer
40 views

How does Wordpress decides how many sizes of an image to create?

Once an image is uploaded to WordPress server, how does it decides how many sizes to create for the same image? I can see for one image, it didn't create any variants, but for a bigger image, it ...
Sankalp Singh's user avatar
0 votes
0 answers
64 views

Add class to all img if they have a certain ACF field

I have an ACF field for image attachments so the user can choose 'rounded border' or 'square border'. How can I apply a class to all images depending on the value of that ACF field? I can do it if the ...
L Waterfield's user avatar
0 votes
1 answer
92 views

How to get comment images stored as serialized comment meta

I want to display images under for each comment but images store in database as serialized a:3:{i:0;i:775;i:1;i:776;i:2;i:777;} I wrote this code print_r (get_comment_meta( $comment->comment_ID , '...
Teymur Abbasov's user avatar
0 votes
0 answers
69 views

How to get a list of all attachements urls for every post of a wordpress installation?

I'd like to retrieve a list of all attachment URLs for all posts of a website. This would bring something like http://example.com/mypost/attachment-1/ http://example.com/mypost/attachment-2/ http://...
Nicolas Guérinet's user avatar
0 votes
1 answer
224 views

Set term on an attachment using wp_set_object_terms and want to display the full term text but it's showing a slug instead

I have a form that visitors use to upload files and fill out information about them and a function that adds those files to the media library and set various fields (including some custom taxonomies) ...
Mike Eng's user avatar
  • 238
1 vote
1 answer
914 views

How to get an attachment id from a filename

I have not been able to find a reliable solution for how to lookup the id for attachments in the media library from a filename as Wordpress does not appear to provide such a function. Most solutions ...
dyg's user avatar
  • 119
0 votes
1 answer
628 views

Update media library image shown in "attachment details" when using wp_insert_attachment to add item to the media library

I'm using the function wp_insert_attachment() to run on a form submission from GravityForms, take a file uploaded in the form, and add it to the WordPress Media Library. Code in functions.php below, ...
Mike Eng's user avatar
  • 238
1 vote
1 answer
337 views

Disable featured image

From the description of the plugin "Hide Featured Image": There are instances when one wants to show featured image on single post and hide it on another post. This plugin will allow you to ...
Miqi180's user avatar
  • 113
1 vote
0 answers
1k views

Insert woocommerce products programmatically with featured image and gallery

I'm inserting WooCommerce products programmatically to the database, but I'm having trouble inserting and linking first image as featured image and multiple images for gallery assigned respectively to ...
Archer's user avatar
  • 11
0 votes
1 answer
123 views

wp_mail Allow Remote Attachments from CDN

I came across a problem with WP_Mail for sending form submissions with file attachments. Our site uses a CDN, so everything uploaded to the site, whether images and media by site builders or documents ...
wpdev215's user avatar
0 votes
1 answer
249 views

Does wp_get_attachment_image_src also work with non-image files?

I wish to get the file path to files other than images like PDF or TXT that are uploaded. Should I use wp_get_attachment_image_src or there's other function more suited for non-image attachments.
ratib90486's user avatar
0 votes
1 answer
147 views

Hook after attachment added and cropped

I am looking for hook, that fires right after image uploaded, cropped for thumbnails and data posted to database. I need it for image optimization after uploading. I tried add_attachment and it fires ...
Denny's user avatar
  • 21
0 votes
0 answers
136 views

PDF Upload from Input Error

I have a custom plugin that creates an input field under each post, that allows users to upload PDF files. $html .= '<input accept="application/pdf" type="file" id="...
Mihnea-Octavian Manolache's user avatar
0 votes
1 answer
43 views

Returning data instead of echoing/printing

New to WordPress (and PHP) and am trying to get this PHP snippet to work with the Code Snippets plugin so I can display all media attachments within my post. It is working, in that it shows the ...
Mason's user avatar
  • 1
1 vote
1 answer
370 views

Display "large" image size and show caption in attachment page

On the attachment page for an image, I'd like to display the image in its "large" size. The current behavior is showing the "medium" size image. I'm using a theme I created from ...
Mike Eng's user avatar
  • 238
0 votes
1 answer
262 views

Do custom post type (CPT) attachments/media store the parent post ID?

Do custom post type attachments store the parent post ID, and if so, how do I retrieve it. I need to prepend the ID of a CPT post to the uploaded media name, eg 123-my-file-name.pdf I do have this ...
Tracy Shorrock's user avatar
0 votes
1 answer
67 views

submit two file input fields in the same form

I have a form which has two file input fields, each input should be submitted in different metabox in custom post type, when I try to submit the form it takes only the first one and ignore the second ...
yahya Elgoud's user avatar
0 votes
1 answer
134 views

How to get all attachment image from post ?? WordPress

I just want to get all atachment image from post with Alt, description, title, size, resotution and how to add DOWNLOAD button? i want to create image downloading website on wordpress for example LINK ...
SauRav's user avatar
  • 5
0 votes
2 answers
379 views

Get all image in media Gallery with alt/title?

Is there a way to fetch the ALT/TITLE of ALL images in the media gallery? I think this would be an easy way for a website to have a Pictures page that just pulls all of the images from the media ...
SauRav's user avatar
  • 5
0 votes
1 answer
208 views

Use rich text editor in 'Edit Media', for attachment media description

I have the following in my functions.php: add_filter( 'wp_editor_settings', function( $settings ){ if( get_post_type() == 'attachment'){ $settings = [ 'wpautop' => true, '...
3x5's user avatar
  • 133
0 votes
0 answers
132 views

Unable to delete related media attachments with deleted post

I want to delete the post attachments too from the 'Media" panel once a custom post is deleted. The post itself gets deleted well, but its media still remains in the wordpress "media" ...
Raging Vids's user avatar

1
2 3 4 5
20