Skip to main content

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
24 views

Get Specific Files (Only Specific Extension Type All Files in Loop ) from Media

I want to get Specific Extension Files from Media of Current Post Uploads—for Instance, .jpg or .png or .pdf, or MP4. (Get Only 1 Extension All Files From Current Post Uploads) Specific Extension ...
Islamic Quran Center's user avatar
0 votes
1 answer
27 views

Define how an attached image is rendered

When inserting an image block to a post, I want to control how the image is actually insterted in HTML. Specifically, I want to replace the autogenerated img element with a picture one, in order to ...
dgnin's user avatar
  • 143
1 vote
0 answers
25 views

How to insert information about the size and type of an attachment into page

I have a page and attachment addes to this page. Now I can output the content of this page with modified link attachment, when each attachment link otput title size and type of attachment like this &...
mardon's user avatar
  • 121
1 vote
1 answer
27 views

wp_get_attachment_links do not modify output for attachment links

I use filter for change link for attachments in a page function custom_attachment_link($markup, $id, $size, $permalink, $icon, $text) { // Get attachment meta data $attachment_meta = ...
mardon's user avatar
  • 121
0 votes
0 answers
18 views

modify the_content() for page to display attachments with own style

I have for display attachmet on page this function $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => -1, ...
mardon's user avatar
  • 121
0 votes
1 answer
33 views

Display file size and type on page or post with attachments

I have page and post in which user upload files as attachment and display link for donwload this files. How I can display after the size link type of uploaded file and the size? After answer in this ...
mardon's user avatar
  • 121
0 votes
0 answers
60 views

Using wp_mail to send attachment from a file stream content

I am using wp_mail to send mail with attachment. The attachment is not stored anywhere. The attachment contents are fetched viacurl request. This is what I wrote. This function below (...
sariDon's user avatar
  • 265
0 votes
1 answer
18 views

How to prevent wordpress from redirecting media attachment page to media page?

For some reason googlebot tried to index my media attachment pages and got redirected to media pages. This seems to be a default wordpress behavior. To recreate it, upload an image called test.jpg to ...
Nicolas Guérinet's user avatar
0 votes
0 answers
20 views

Can`t attach image to a multiple posts

It seems this question was asked multiple times in the past, but what is the current situation. Is the attachment of an image to a multiple posts possble? Right now when i attach image to more than ...
Konstantin Kurtev's user avatar
0 votes
1 answer
40 views

How to add year and month path to old attachment images?

I was using only uploads folder for attachment images. After a while, I started using also Year and Month folder. But I did realize something today. And that is, new uploads works perfectly but old ...
Aslan's user avatar
  • 13
0 votes
1 answer
27 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
82 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
44 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
206 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
10 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
  • 775
0 votes
1 answer
109 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,938
0 votes
1 answer
68 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
111 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
  • 215
0 votes
0 answers
23 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
  • 215
0 votes
2 answers
553 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
64 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
129 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
1 vote
1 answer
89 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
2 answers
145 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
221 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
1 vote
0 answers
39 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
  • 268
1 vote
0 answers
44 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
1 vote
1 answer
562 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,938
0 votes
1 answer
655 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
71 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
1 answer
44 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
1k 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
121 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
101 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
107 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
96 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
340 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
  • 268
1 vote
1 answer
1k 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
  • 129
0 votes
1 answer
941 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
  • 268
1 vote
1 answer
505 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
2k 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
132 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
336 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
219 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
180 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
84 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
444 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
  • 268
0 votes
1 answer
402 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
83 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
364 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

1
2 3 4 5
21