Add a metabox to list all attachments on a post, page or CPT

Cleanshot 2023 06 16 At 16.12.09@2x

Sometimes you just wanna clearly see what stuff (images, videos, media) is attached to a post. Well now you can! This Post Attachments Metabox makes it easy to manage and view attachments on any post, page or even custom post types.

What it does…

The Post Attachments Metabox is a handy WordPress snippet that adds a custom metabox to your post editor screen. This metabox displays a list of all the attachments (images, videos, media) associated with the post, allowing you to easily see what’s attached without navigating through the media library.

Why it does it…

Having a clear overview of the attachments connected to a post is crucial for content creators and editors. It helps ensure that the right media is being used, eliminates confusion, and saves time searching for the correct files. With the Post Attachments Metabox, you can effortlessly manage and access your attachments directly from the post editor.

How it does it…

The magic behind the Post Attachments Metabox lies in its elegant implementation. The code creates a custom metabox using the add_meta_box() function, which allows it to be displayed on posts, pages, and any custom post types. It queries the attachments associated with the post using get_posts() and retrieves their URLs and other relevant details. Then, it dynamically generates an HTML list displaying the attachments, including a thumbnail, file URL, and an edit link for each item.

This powerful yet lightweight solution enhances your content creation experience, making it a breeze to manage and view your post attachments without leaving the editor. It brings convenience and efficiency to your workflow, ensuring that you have a clear understanding of the media assets attached to your posts.

With the Post Attachments Metabox, you can take control of your content and enjoy a seamless attachment management experience in WordPress. And all without adding another plugin!

Use the JSON file for easily importing into your CodeSnippetsPro plugin. Use the PHP file or just copy/paste the code sample into your functions.php if you’re not using CodeSnippetsPro.

Related Snips

See the code on github…

Leave a Reply

Your email address will not be published. Required fields are marked *