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.

learn more… | top users | synonyms

14
votes
2answers
3k views

Turn a URL into an Attachment / Post ID

Is there any way I can take a URL of an image and find the attachment or post id of that image in the database? Here is the situation: I'm in a loop going over all the 'img' tags that are surrounded ...
2
votes
4answers
28k views

How to Fix HTTP Error When Uploading Images?

I am using WordPress 3.4.1 on Ubuntu 12.04 using Apache and PHP 5.3.X When I login to the dashboard and add a new post. Then try uploading an image to set as a featured image, I get a red box with a ...
6
votes
3answers
18k views

Submit post and upload image from front-end

I am trying to do something similar to the above question. I am trying to make users post and upload images from front-end. I have already done the post form and its working. I just followed and ...
12
votes
5answers
5k views

Can I add a Category Metabox to attachment?

I am using register_taxonomy_for_object_type() to add the Category taxonomy field to Media uploads (attachments). I'm using this code to do so: add_action('init', 'reg_tax'); function reg_tax() { ...
5
votes
1answer
2k views

Changing attachment urls?

How can I change the format of attachment page urls from /[post-url]/[attachment-name]/ to /media/[attachment-name]/? I understand that I can override the output of get_attachment_link via the ...
1
vote
1answer
806 views

How to paginate attachments in a secondary query as gallery?

I have this code that shows all images attached to my post-type. Is there a way to paginate those? I have like 25 pics and I wan't to avoid scroll as much as I can. Code: <div class="galleries ...
12
votes
2answers
5k views

Creating an Image-Centric Custom Post Type?

Does anyone have any tips for creating an image-centric custom post type? To elaborate, my blog has rotating header images, shown below: The two images in the top left are randomized, and exist as ...
3
votes
4answers
6k views

How to restrict access to uploaded files?

I have a restricted area on a website that can only be accessed by logged in users. For that I created a page template with a 'current_user_can()' condition. My problem is that the documents attached ...
5
votes
1answer
4k views

simple solution for restricting access to (some) uploads/downloads

Initial Situation For a site I'm setting up I was looking into the whole field of securing uploads/downloads and restricting access to them based on user roles/capabilities. Of course I have read ...
5
votes
3answers
4k views

How to use taxonomies on attachments with the new Media Library?

WordPress 3.5 changed the media management and now the Media Library edit screen uses the default post type UI. Taxonomies are very useful for WP installs with different users and attachments, giving ...
1
vote
1answer
1k views

exposing attachment uploading to the front end — delicate

i'm probably breaking a few common sense rules here. is there a way to utilize wordpress' bake in attachment file handling for an upload form within a theme template? yes, the front end -- i ...
1
vote
3answers
4k views

Applying automatic link class to images embedded to posts

I'd really love to be able to conditionally apply a CSS class to link elements of images embedded into posts, but I can't seem to figure this one out. Basically what I'd like to achieve is to replace ...
5
votes
2answers
712 views

Delete Associated Media Upon Page Deletion

Note Use at your own risk, it is buggy and I have run across a couple instances where it would delete ALL attachments. Unsure why. Is it possible to delete media associated with a page when that ...
10
votes
2answers
21k views

How To Retrieve An Image Attachment's Alt Text?

I am using an attachment.php file to show large versions of images that have been clicked on elsewhere. I'd like to pull the image alt text as a caption under the image with javascript, but the alt ...
5
votes
4answers
3k views

Change attachment filename

Is there a function that allows me to change the filename of an attachment, based on the Attachment ID I have? Thanks! Dennis
5
votes
3answers
5k views

Get first image in a post

I am using this code directly from the codex. function echo_first_image ($postID) { $args = array( 'numberposts' => 1, 'order'=> 'ASC', 'post_mime_type' ...
3
votes
2answers
3k views

Set Featured Image Front Frontend Form

I have been struggling for days to figure this one out. I have successfully implemented a form to submit posts from the front end of my site. ButI can't figure out how to make the image uploads work. ...
4
votes
1answer
2k views

How to paginate wordpress [gallery] shortcode?

I am using wordpress gallery shortcode [gallery] I was wondering if there is anyway to paginate them without using a plugin.
2
votes
1answer
2k views

Retrieving a custom link on an attachment

I wanted to link images in a gallery to a custom URL. I know I could add an extra field and do it this way I found this ticket on Trac, though, that modifies the "Link URL" field to accept custom ...
0
votes
2answers
3k views

Automatically wrap post image in div

In regards to image attachments inserted into a post, I would like to wrap the img tag inside a div tag for specific design purpose. Is there a way to do this automatically after attaching the image ...
5
votes
1answer
10k views

How to get attachment file name not attachment URL

I'm using this code to list the image attachments of a post: <select name="chb_homes_for_sale_specifics_floor_plan" style="width:100%;"> <option ...
3
votes
1answer
2k views

media_sideload_image generates blank?

I'm creating a custom post form that is supposed to take an external image and uploads it to the media library and attach it to that post. This should be possible by using media_sideload_image, but ...
3
votes
4answers
4k views

custom fields for attachments?

is it possible to add extra fields via the functions.php script for attachments in wordpress? Tried loads of examples but none seem to work. Worried an existing plugin might be affecting my attempts ...
6
votes
2answers
5k views

Attaching media to custom posts without editor

I'm creating a custom post type, "gallery", in which the admin should be able to upload images (these images would be attached to the post). The thing is that the "editor" meta box is disabled for ...
2
votes
4answers
5k views

using upload image with media_handle_upload .. but !

I'm tring to upload image in wordpress by using some function .. I found the way to upload images but there are one problem .. when the user upload his image , wordpress create more than one image ...
5
votes
1answer
1k views

Trying to hide buttons from Attachment window

To simplify the Media Library layout to users when uploading an image, sometimes i hide the following fields: function myAttachmentFields($form_fields, $post) { if ( ...
5
votes
6answers
7k views

Disable image attachment links

Is there a way to disable image attachment links trought a filter in functions.php or something ? I know it's possible to do it manually when you add an image to a post but I want to disable this ...
1
vote
2answers
3k views

How to add media from front-end to an existing post?

Golden Apples Design created (as far as I know) the media upload function that many people on WP.A and elsewhere seem to recommend. But all of the Q&As I can find on StackExchange deal with ...
7
votes
4answers
5k views

Broken? WP_Query and “attachment” as a post type

I have a gallery attached to a page. On that page, I'm running the following query: $events_gallery = new WP_Query( // Start a new query for our videos array( 'post_parent' => $post->ID, // ...
6
votes
1answer
5k views

remove links from images using functions.php

I am looking for a way to remove the attachment link from images in the post content. I would like to add this to the functions.php in my theme. I know you can disable this in the post on a per ...
2
votes
2answers
4k views

Add_Filter example for wp_get_attachment_link

Let me preface by saying I don't really understand Add_Filter, but I think that I want to be using it here. If not please let me know. I want to modify wp_get_attachment_link so that the link url ...
1
vote
1answer
1k views

Creating a multi-file upload form on the front end for attachments

I am trying to create a public form where users can upload multiple images to be attached to a particular post. I am able to get it to work with single images thanks to this post at Golden Apples ...
0
votes
1answer
2k views

attachment url rewrite

i want to change the address of the file attachment link to wordpress [example: http://www.sitename.com/category/sub-category/article.html/attachment/image etc.]. i did research on the subject ...
6
votes
2answers
7k views

Get all image from single page using this query

I'm having some trouble with this sample widget code. I want to get all images (Minus the post thumbnail) from a page called "Gallery" but for some reason this is pulling all uploaded images from the ...
3
votes
1answer
357 views

Bulk term assignment for attachment taxonomies

I've created a custom taxonomy for attachments. Everything ok, but now I want the ability to bulk assign its terms to attachments using the default wordpress media admin ('upload.php') bulk actions. ...
2
votes
2answers
3k views

How to replace “wp-content/blogs.dir” with “media” for attachment permalinks?

How to replace "wp-content/blogs.dir" with "media" for attachment permalinks in a multisite environment? This is how links look now: ...
1
vote
1answer
7k views

get images attached to post

I want to have the ability to use pictures from the media library in a jquery slider on the home page so that it's easy for someone else to update the pictures without having to hardcode it. I have ...
1
vote
1answer
2k views

Gel all image from certain post type

I've found similar questions here, however I can't modify the answers to get images only from a certain post type - as the post type in those examples are "attachment" and not the name of a custom ...
0
votes
1answer
806 views

How to display a shortcode caption somewhere other than the_content

I want to disable shortcode captions for posts in one of my themes, and display the content elsewhere, such as in a sidebar. The images aren't uploaded to wordpress, but they're linked-to using the ...
3
votes
1answer
281 views

How do I delete all generated images from my server except those currently used in posts

I have a new set of image sizes for my site's in-development theme. My server is filled with old image sizes, most of which have never been used. You've heard this one before, right? The Question How ...
2
votes
4answers
3k views

get attachments for all posts of particular post type

I'm making a widget that shows a set of images from recent custom posts. I want to run the following query: SELECT p.* FROM wp_posts p WHERE post_type='attachment' AND post_mime_type LIKE 'image%' ...
1
vote
2answers
2k views

How can I remove fields in the attachment editor?

Is it possible to remove a default attachment field from the attachment editor, for example the "Caption" field ? To give you some context, I'm trying to build a custom attachment editor page. I ...
0
votes
1answer
835 views

Get the post attached to a image attachment

Assuming I know the image attachment ID, how can I get the post permalink to which is attached (if any) ?
6
votes
3answers
5k views

Getting Path To Uploaded Attachment Image After Upload

After you have uploaded an attachment in Wordpress using the media upload screen, is there a hook or filter I can run after the image has been uploaded where I can get the path to the uploaded image ...
0
votes
1answer
1k views

File upload from front-end form (as attachment) not working

I have a front-end form that is supposed to allow the user to upload a CV which is then sent along with the rest of the form as an attachment. To do so I have used wp_handle_upload() like so: if ...
0
votes
1answer
641 views

Add suffix to filename of uploaded images

I registered 3 custom image sizes (Double sized, for retina displays) with add_image_size: thumbnail@2x, medium@2x and large@2x. function retina_image_sizes() { $retina_sizes = array( ...
0
votes
2answers
798 views

ID of images from gallery

Does anyone know how to get ID's of images from wordpress gallery in post? I have search entire internet and there is nothing to this subject.
0
votes
3answers
3k views

Change Attachment Post URLs to File URLs

I have a client with a very image heavy blog. Every time they upload images in their posts they are using the Attachment Post URL for the link instead of the File URL. The problem with this is that ...
0
votes
2answers
1k views

Remove “attachment/” from the URL of attachment pages

Currently, the media for a page on /hello-world/ is shown on /hello-world/attachment/image-name/. Is it possible to remove attachment from this URL, and make it /hello-world/image-name/?
-1
votes
1answer
144 views

How can I attach files without using a plugin?

I want to add files from my site or from external links with files to any of my posts, and be able to add the size of the file and choose which ones it will do "File Force" and which not. I want to ...