1

I've never built a plugin before. I'm very new to WP in general, but I was wondering what the process of turning a custom post type and template I made into a plugin?

Here's the thing I'm trying to do.

I made a custom post type called "gallery" using ACF and CPTUI.

It's a masonry style gallery, with lightbox, that can contain mixed media content, such as videos, images, and external links (possibly iFrames though I haven't added that yet).

The user has a repeater field that they can add title, description, picture, link, and video to. If they upload a video, then it will display a soundless, looping video inside the gallery, just like it would an image. This is basically so mp4 files can be inserted into a library instead of gifs, for the purpose of being optimized, but also allowing motion graphics etc type work to be displayed alongside static work.

If there's a link, instead of opening the lightbox, it will open a new window with the linked page in it. This is so I can have a gallery with preview images of websites I've made, that when click, just open the website in a new tab etc.

I want to convert this into a plugin so that I can just insert multiple galleries wherever I want to, inside of a blog post using the WP post editor etc. Is this possible? How would I do this?

1 Answer 1

3

Take the file the custom post type is registered in, put it in the plugins folder, and add a comment at the top, e.g.:

<?php
/**
 * Plugin Name: David A. Frenchs Custom Post Type Plugin
 **/

Save and visit the plugins page to activate it, and that's it! A plugin is just a file with a comment at the top. You can put it inside a folder and include other files into your plugin too, WP will search for the comment at the top of the file and load that one.

Just remember to prefix your plugins name, if somebody else has the same idea and uploads a plugin with the same folder/file name to wordpress.org it'll trigger the updater

5
  • Wow! That's super easy! If I want to make it so that I can insert a gallery into a normal blog post, or maybe even insert multiple galleries into different parts of a blog post, how do I go about doing that with my plugin? Commented Sep 27, 2017 at 19:16
  • The same way you would in a theme, but that's beyond the scope of your question, you can ask a new question on the site. We have a 1 question per question policy else answers would never get marked as the solution
    – Tom J Nowell
    Commented Sep 27, 2017 at 22:51
  • Cool. thanks. Also I figured out a better solution than trying to make it into a plugin :) Thanks for the help! Commented Sep 28, 2017 at 3:02
  • Just keep in mind that putting custom post types in your theme removes data portability and locks the user into your theme. Any theme switch will involve potential data loss
    – Tom J Nowell
    Commented Sep 28, 2017 at 12:35
  • Ah that's a good point. I'm only building this for myself right now, but I'm going to start learning plugin stuff soon so that will change my approach in the future I'm sure. Thanks again! Commented Sep 28, 2017 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.