A WordPress plugin to register media selection meta boxes., (*1)
Contributors: Brady Vercher
Requires: 3.5
Tested up to: 3.5.1
License: GPL-2.0+, (*2)
With the release of WordPress 3.5, an effort was made to decouple attachments from the posts where they were uploaded, which was a shift from previous versions, and a greater emphasis was placed on the [gallery]
shortcode. Backward compatibility was maintained, but it became a little less intuitive to manage a gallery of images that were simply attached to a post. In any case it has always been a little difficult to select multiple featured images, or multiple galleries, for use in different areas in a template., (*3)
Metamedia allows for registering simple meta boxes like the "Featured Image" meta box for selecting a single image or gallery of images to be stored in a post meta field for easy retrieval and usage in templates. It can be used with any post type and uses the native media frame., (*4)
An example gallery meta box. The images can be sorted directly in the meta box., (*5)
An example meta box with custom labels for selecting a single image., (*6)
Usage
To add a meta box similar to the "Featured Post" meta box, simply register it using register_metamedia_metabox()
like this:, (*7)
function themename_register_metamedia() {
if ( ! is_admin() || ! function_exists( 'register_metamedia_meta_box' ) ) {
return;
}
// Register a meta box for assigning a 'hero' image to posts.
register_metamedia_meta_box( 'hero', 'post' );
}
add_action( 'init', 'themename_register_metamedia' );
Now in a template, the image ID can be retrieved using get_post_meta( $post_id, 'hero', true )
., (*8)
Methods
The parameters for both methods are the same. Most labels and properties of registered meta boxes and the media modal can be customized using the optional $args
parameter., (*9)
register_metamedia_meta_box( $meta_key, $post_type, $args = array() )
, (*10)
register_metamedia_gallery_meta_box( $meta_key, $post_type, $args = array() )
, (*11)
Arguments
Key |
Description |
Example |
meta_box_title |
The title of the meta box. |
Hero Image |
meta_box_context |
Where the meta box should appear. |
side |
choose_label |
Label of the button used to open the media frame. |
Select Image |
remove_label |
Label of the link used to remove a selected image. |
Remove image |
frame_title |
The title of the media frame. |
2-10 |
frame_button |
The label of the button used to select an image in the media frame. |
Update Image |
Some arguments may not work with the gallery meta box. Additional arguments are available for more advanced usage., (*12)
Installation
Metamedia is available in the WordPress plugin repository, so it can be installed from within your admin panel like any other plugin. You may also download it directly from GitHub using one of the following methods:, (*13)
Upload
- Download the latest release from GitHub.
- Go to the Plugins → Add New screen in your WordPress admin panel and click the Upload tab at the top.
- Upload the zipped archive.
- Click the Activate Plugin link after installation completes.
Manual
- Download the latest release from GitHub.
- Unzip the archive.
- Copy the folder to
/wp-content/plugins/
.
- Go to the Plugins screen in your WordPress admin panel and click the Activate link under Metamedia.
Read the Codex for more information about installing plugins manually., (*14)
Git
Clone this repository in /wp-content/plugins/
:, (*15)
git clone git@github.com:cedaro/metamedia.git
, (*16)
Then go to the Plugins screen in your WordPress admin panel and click the Activate link under Metamedia., (*17)