X

Display a Custom Post Type’s Media Library Inline

Snippets by IsItWP

Are you looking for a way to display a custom post type’s media library inline? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display a custom post type’s media library inline in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

  define('MY_POST_TYPE', 'my');
  define('MY_POST_SLUG', 'gallery');

  function my_register_post_type () {
  	$args = array (
  		'label' => 'Gallery',
  		'supports' => array( 'title', 'excerpt','thumbnail' ),
  		'register_meta_box_cb' => 'my_meta_box_cb',
  		'show_ui' => true,
  		'query_var' => true
  	);
  	register_post_type( MY_POST_TYPE , $args );
  }
  add_action( 'init', 'my_register_post_type' );

  function my_meta_box_cb () {
  	add_meta_box( MY_POST_TYPE . '_details' , 'Media Library', 'my_meta_box_details', MY_POST_TYPE, 'normal', 'high' );
  }

  function my_meta_box_details () {
  	global $post;
    $post_ID = $post->ID; 
  	printf( "<iframe frameborder='0' src=' %s ' style='width: 100%%; height: 400px;'> </iframe>", get_upload_iframe_src('media') );
  }

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 18 Jetpack alternatives to get the features without bloat and how to increase maximum file upload size in WordPress.

Comments   Leave a Reply

  1. Francisco Javier Pardo Rebolle November 7, 2013 at 8:01 pm

    Thanks… very useful

  2. Thanks Kevin.

  3. If you want your booth to exude a sophisticated,
    polished style, consider soft flooring that mimics the look of a beautiful
    hardwood floor. If your company’s image is more fun loving, a custom trade show
    carpet in bold color blocks is a great choice. If you’re selling tools or auto
    parts, consider rubber matting from recycled tires – it’s durable and
    eco-friendly as well.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!