Made Thing Avatar

17 Notes

Solved: Moving image attachments between pages in WordPress

Uploading and attaching an image to a page is dead simple in WordPress 3+. Unfortunately, changing the page that an image is attached to isn’t so simple. You can either delete the image and upload it again to a new page, or you can open up phpMyAdmin and get to know your database tables. I frequently use WordPress pages as defacto image galleries, and frequently need to move images between those pages, making this a frequent pain in my keister.

No more. Today I finally coded a quick solution to the problem.

This code adds a drop-down menu to the Media > Edit screen that lists all of the pages in your WordPress site, and allows you to choose between them. Saving your selection reassigns the image attachment to the selected page.

Here’s what the new Media > Edit screen looks like:

Note that the drop-down menu only appears for images that were originally attached to a page. It will not appear inside the Media > Edit screen for images that were originally assigned to a post. (The code could easily be adapted to include both posts and pages, though.)

To use this, copy the code, and paste it into the functions.php file within your WordPress theme to activate it.

This code draws heavily on Andy Blackwell’s tutorial on creating custom fields for image attachments at Nettuts, which was the only documentation I could find on the attachment_fields_to_edit and attachment_fields_to_save hooks.

Probably I’ll package all this up into a handy plugin as soon as I get a minute. Until then, get to know your functions.php file. It’s a terribly handy little thing.

Oh, and in case I forgot to mention it, I’m now available for contract work.

Update: Here’s another solution for detaching and reattaching images from posts.

Replies

Likes

  1. madething posted this

 

Reblogs