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
2answers
990 views

wp_mail doen't send mails whit attachment

On my site I hava two forms witch send email. The one whit no attachment needed is sent correnctly, but the other ony witch has an attachment does not get sent. I am using SMTP config whit Postman ...
0
votes
0answers
1k views

wp_get_attachment_metadata is empty

We have a website with images that do not contain any attachment metadata. I set out to create my own function that checks if there is metadata, and if there is not any, it will create it. ...
0
votes
1answer
26 views

Create page from post attachments

WordPress provides attachment pages out of the box. But is it somehow possible to have page with listing of all attachments that are connected to a certain post? It should basically work as a gallery ...
4
votes
1answer
275 views

Give attachments an archive page

I'm trying to override WP's default URL structure for attachments where, if they're attached to a post, the URL is /post-slug/attachment-slug/ and if not it's simply /attachment-slug/. What I'd like ...
0
votes
1answer
40 views

Wordpress Attachments with old images

I have a situation where I need to get all the images used in some kind of post. Now the problem is that attachments is saved only when I upload new image, if I use some other image which was already ...
3
votes
0answers
1k views

Attachment page 404 not found when image is attached to post

I have this new WP webiste I’m working on. Today I was going to design the attachment.php page so that my image pages would look nice, but found that I was getting a 404 for all of them actually. I’ve ...
6
votes
1answer
345 views

Can I use the wp media uploader for my own plugin?

I'd like to use the media uploader within my own plugin and I was wondering if this was possible? Essentially I'd like the same functionality as found in media-new.php so I can have the same ...
1
vote
1answer
2k views

Add a new data attribute in <img> tag

I would like to use Qazy Lazy load and I need to include new data attribute data-qazy="true" inside all img tags. I tried to include with this function, but it only applies for sidebar images and ...
8
votes
1answer
18k views

Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails

I am running the latest WordPress version (4.6) on a LAMP server (shared hosting) with PHP version 5.6.12. I am trying to programmatically add 10 images, uploaded with ftp to the wp-uploads directory,...
6
votes
1answer
7k views

Disable Attachment Pages Completely

I would like to disable all attachment pages completely. I Googled it, but there's just information on how to redirect to parent post or homepage. That's not what I would call an elegant solution. Why ...
2
votes
2answers
136 views

Adding File Extensions to Attachment Page Permalinks

Introduction When uploading a file (stackexchange.jpg) to the media library in a WordPress site, there are two relevant links. Direct link to filehttp://example.com/wp-content/uploads/stackexchange....
0
votes
1answer
136 views

Remove attachment page for audio media type only

There is code below to redirect an attachment, but what about just for specific media types like audio or videos? function sar_attachment_redirect() { global $post; if ( is_attachment() ...
0
votes
1answer
969 views

Get image attachment to a post outside the loop?

What's the best way to display the URL to an image that's attached to a post and is outside the loop? This is the code I'm using to display the results: <?php foreach($duplicates as $postID) { ?&...
6
votes
1answer
2k views

Open media frame and select an attachment

I'm using the following piece of code to open a media frame when clicking a link with a data-attachment_id attribute. This attribute holds the id of an attachment that I want to select when the frame ...
0
votes
1answer
44 views

_d_improd_ directory in uploads breaking site images

I've encountered this weird problem. On a site we're trying to help out on some of their URLs for attachments have become broken. URL in post_content wp-content/uploads/2016/04/_d_improd_/...
3
votes
1answer
44 views

How can I add a fifth option to the alignment picker?

I'd like to have the following options in the image alignment picker: Left Right Center Full None Obviously four of those are there by default, but the "full" one doesn't currently exist. The idea ...
0
votes
2answers
3k views

Attachment Page Permalink/URL Rewrite Issue. How to change the actual rewriting?

I have a problem understanding the behavior of the Attachment Page Permalinks Into Setting-->Permalinks I have set http://www.example.com/sample-post/ as the preferred setting. When I upload an ...
1
vote
0answers
39 views

How do I get all attachments that are used in the current post, not just the children?

wp_get_attachment_url() is the method used to fetch the attachments. Currently I am passing the attachment IDs fetched by $attachments = get_children( array( post_parent' => ...
0
votes
0answers
28 views

How can I add an “Attach image to this post/page” link on the Add Media lightbox?

How can I add an "Attach image to this post/page" link on the Add Media lightbox? My theme uses attached images to generate sliders. I want to be able to attach images from Media Library to the ...
2
votes
3answers
3k views

Get attachment ID of author_meta image - Attachment Metadata

I've created a custom field in user profile where upload a profile image. It's very simple. To create fields I've used: add_action( 'show_user_profile', 'cover_image_function' ); add_action( '...
2
votes
1answer
659 views

Is it possible to modify the media library admin screen?

I've been searching for a few hours now but I can't seem to find a solution to this. I'm developing a plugin and I'd like to be able to add custom text underneath the admin media library heading. I ...
1
vote
1answer
681 views

Get post attached image to display in admin dashboard

I've searched awhile for a solution on how to get the attached image in the post's editor to display within the dashboard but I am running into an issue. I've seen how to do this and can do this with ...
0
votes
2answers
79 views

Check if author or uploader id of the attachment(uploaded) image is match?

I am trying to write a function to upload and delete images on frontend with dropzonejs uploader, and so far i managed to make everything work. But the problem is that i need to secure it that the ...
0
votes
1answer
572 views

Resize $term attachment using url

I'm using this plugin for attaching an image to a custom taxonomy. The plugin's function returns the attached term's image as following: function get_wp_term_image($term_id){ return get_option('...
1
vote
1answer
699 views

Update attachment metadata fails

Updating attachment title and description metadata with wp_ajax breaks all previous datas and structure of attachment, my php code: add_action( 'wp_ajax_update_attachment', '...
2
votes
1answer
4k views

Use Timber/Twig to pull an image by image ID [closed]

Is it possible to use Twig to pull an image by ID, or only to pull the post.thumbnail? The Twig docs don't seem to cover any other image need and I'd like to specify a backup image in case no post....
1
vote
0answers
66 views

Searching Custom Post Types

I am trying to create a search template to search attachments uploaded to a custom post type called folders. This is what I have so far: if ( $post->post_type == 'attachment' && $post-...
2
votes
2answers
16k views

How to upload image from front end and save in media library?

I am working on a plugin .I want to upload image from front end i.e by input type="file".I did lot of google for it but could not upload image .Here is my code for uploading image <form method="...
0
votes
1answer
210 views

Add custom field to attachments in a specific category

I have a working function that adds a meta field to all attachments (so I can enter the url of a video). I would like this field to populate only on attachments in the "video" category. I've tried ...
0
votes
1answer
911 views

How to add a caption to an image attachment in a file list?

I've tried various things and can't get the captions to show up in my gallery. I'm using CMB2's file list to output image attachments. I hope this question is pertinent enough to this forum as I think ...
1
vote
0answers
34 views

Images attached to posts from library link to 404 error page

Just building a theme but I am stuck with attachment images. When I add images from the library to posts (or pages) and link them to the "attachment page" I get a 404 error. The link is like "http://...
0
votes
1answer
835 views

Could not get attachment using wp_mail

I am trying to create a form which can be sent by users with an attachment. The form works fine and sending the emails when it is submitted but without the attached file. my form is : <form ...
0
votes
1answer
182 views

How to get the filename from file system and create a download link?

I have a custom page template. This template have a custom form, the user can upload a file in that form and input his/her personal infos. The file will save in the file system. I want to create a ...
1
vote
0answers
1k views

Posts and Attachments with “Published” status in Search

I would like the search to show only published posts and attachments (the attachments are photographs taken directly from the media library). The trouble is, when I specify that the post_status must ...
1
vote
1answer
87 views

Wordpress Search Results for Multiple Post Types

I want to show both posts and attachments in the search results. Basically, I need something that says if the post has a thumbnail, show it. else show the attachment image (since they don't have ...
2
votes
1answer
1k views

How to set an attachments parent post id in code?

I've inherited an imported wordpress site with a few issue. I have a list of attahment ids and post ids but I need to re-connect them in the code. I've got a list of all attachemnt like this: $...
0
votes
1answer
2k views

Get Attachment Category Name

How can I call the name of an attachment category? Something that would look like <?php get_attachment_category_name ?> or $attachment->category_name This would simply output the name of ...
0
votes
1answer
426 views

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 ...
1
vote
1answer
63 views

Attachment changing page's permalink - $post not resetting?

I have a function that I use to populate from checkboxes on a page's edit view (post.php?action=edit). I call this function when I render a metabox on the editor page. function ...
0
votes
2answers
2k views

Using $_FILES variable into the same function for uploading images and files

I want start saying that I'm learning and I'm trying to understand the use of $_FILES and $file_handler which are making me crazy into this function to upload attachments from a frontend form. What ...
0
votes
2answers
1k views

Upload images and attachments from frontend form

I'm not very expert of wordpress and I'm trying to create a frontend form sending information to my php function through ajax. I'd need help about uploading images and files as attachments of the post....
5
votes
1answer
385 views

Validate alt text for attachments?

How can I require users to enter alt text when adding attachments? Alt text is surprisingly buried; the only way I've been able to retrieve the alt text at all is via the wp_get_attachment_image() ...
0
votes
1answer
49 views

Attachments plugin cannot click media library button [closed]

I have installed the Attachments plugin (version 3.5.7) to upload multiple images to a post in my post type 'shop'. The problem: For some reason I cannot click the insert button of the media library ...
0
votes
1answer
731 views

Help to upload post attachments from Ajax

My problem is that I cannot upload post attachments from a frontend form. I send data through AJAX to my php files containing functions. Let me be clear: everything is working great, the post is ...
1
vote
0answers
369 views

Get attachments for posts that belongs to a specific category

I am trying to get images which are used by a post belonging to the specific category. For example if I have plants, mushrooms and animals as post categories, I only need to retrieve images that are ...
0
votes
1answer
345 views

Search by Attachment ID

I'm building a stock photo page for my company where we upload all photos our staff created so that it can be used later. It shows the ID of the image by post->ID so that users can see it, note it and ...
6
votes
1answer
1k views

Add custom class to attachment in media library grid mode

In the above screenshot we are in the media library with grid mode active. I want to add a custom class depending on the attachment filter wp_prepare_attachment_for_js. For example i hook to the ...
0
votes
2answers
207 views

Looking to limit file attachment downloads

I am using WP user front end plugin to let users submit posts to my site that includes a file on that post that other users can download. The problem is I want user-a to only be able to download a ...
0
votes
2answers
193 views

How to get Attachments(image) with specific width\height ratio

I need to get attachment images with horizontal orientation. I tried to use Meta_Query but I don't know how to compare two values (width and height) from one associative array that is in wp_postmeta ...
0
votes
1answer
273 views

Get post embedded image caption

I am trying to get the caption of post embedded images to then use on a lightbox. This is my code: function my_theme_prefix_content_gallery( $content ) { global $post; $args = array( ...

1
3 4
5
6 7
19