Adding custom fields to attachments

WordPress has extended functionality that allows to create media library. As WordPress developers sometimes we need add custom fields to library items. Today I would like to describe how to add custom fields to attachments.
Adding custom fields to attachments

1. Add the code that displays custom field on media library popup window and on edit media page. Insert this piece of code into your plugin file (if you develop plugin) or into function.php (if you develop theme).

2. Handle library item updating. Insert this piece of code into your plugin file (if you develop plugin) or into function.php (if you develop theme).

If you wish, you can add new column to Media Library table:
Adding custom field column to media library table

Insert this piece of code into your plugin file (if you develop plugin) or into function.php (if you develop theme).

That’s it. Nothing difficult. 🙂

PS: Please note, “ic-custom-field” is a custom field slug/id. You can use any unique string instead of “ic-custom-field”.

Comments are closed.

Login Contact Me Any Widgets Social Subscribe
×
 
Thank you for subscription!
×
 
Thank you! Your message has been submitted to us.
×

Calendar

May 2019
M T W T F S S
« Nov    
 12345
6789101112
13141516171819
20212223242526
2728293031  
×
×
×