Host Your WordPress Plugins on GitHub and Automate Plugin Packaging

Let’s talk plugin distribution.

Hosting your plugins on GitHub provides powerful benefits such as version control, collaboration, and easy sharing.

But distributing your plugin as a proper .zip file for users can be tedious, especially when you need to exclude unnecessary files like .git folders, node_modules , and .DS_Store .

This guide walks you through:

  1. Hosting your WordPress plugins on GitHub.
  2. Automating the creation of .zip files, saving them one level up in the main plugins folder.
Let's do this - GIF

Step 1: Host Your Plugin on GitHub

1.1. Create a New Repository

Log in to your GitHub account and create a new repository:

  • Go to github.com/new.
  • Name your repository (e.g., my-awesome-plugin ).
  • Optionally add a description.
  • Set it to Public if you want to share the plugin or Private for internal use.

Initialize the repository with:

  • A README.md file to describe your plugin.
  • A .gitignore file (select “WordPress” from the GitHub template list).

    1.2. Push Your Plugin Code to GitHub

    If your plugin already exists locally:

    Open your terminal and navigate to your plugin folder:

    cd /path/to/your/plugin

    Initialize Git and link it to your GitHub repository:

    git init git remote add origin https://github.com/your-username/my-awesome-plugin.git

    Add and commit your plugin files:

    git add . git commit -m "Initial commit"

    Push your code to GitHub:

    git branch -M main git push -u origin main

      1.3. Create a GitHub Release for Easy Downloads

      GitHub automatically generates source code downloads for your repository, but these include the .git folder and may add a -main suffix to your plugin folder, which can break WordPress installation. To avoid this:

      1. Go to the “Releases” section of your GitHub repository.
      2. Click “Draft a new release”.
      3. Add a version tag (e.g., v1.0.0 ), title, and description.
      4. Upload your plugin .zip file (see the next section for how to create it).
      5. Publish the release.

      Your .zip file will now be available for download, and GitHub will track the number of downloads.

      I'll show you automated - GIF - spongebob squarepants

      Step 2: Automate Plugin Packaging with a Bash Script

      Manually zipping your plugin every time you update it can be time-consuming. This script simplifies the process and saves the .zip file in the parent plugins folder for better organization.

      2.1. Create the Bash Script

      Open your terminal and create a new bash script:

      nano ~/zipplugin.sh

      Add the following script to the file:

      Save and close the file by pressing CTRL+O , then CTRL+X .

      Make the script executable:

      chmod +x ~/zipplugin.sh

      2.2. Add an Alias for Convenience

      To make the script easier to use, add an alias to your shell configuration file.

      Open your shell configuration file ( ~/.bashrc or ~/.zshrc ):

      nano ~/.bashrc

      Add the following alias:

      alias zipplugin="~/zipplugin.sh"

      Save and reload your shell:

      source ~/.bashrc

        2.3. Use the Script

        Navigate to your plugin directory:

        cd /path/to/plugins/my-plugin

        Run the script to create a .zip file with the default folder name and exclusions:

        zipplugin

        The .zip file will be saved in the parent plugins directory:

        /path/to/plugins/my-plugin.zip

        Optionally specify a custom plugin name:

        zipplugin custom-plugin-name

        Customize the exclusions by adding a second argument:

        zipplugin custom-plugin-name "*.env/* *test*"

        SEND IT - GIF

        Step 3: Share Your Plugin

        Now that your .zip file is ready, upload it to your GitHub release 💪💯

        This makes sure that users can download and install your plugin without encountering issues like unnecessary files or incorrectly named folders.

        1. Go to your GitHub repository.
        2. Navigate to the “Releases” section.
        3. Upload your .zip file to the release.

        Comments

        8 responses to “Host Your WordPress Plugins on GitHub and Automate Plugin Packaging”

          1. Robert Avatar

            I haven’t used GitHub Actions enough yet for this to speak on it, and I typically like to unzip the one locally just to verify it’s all correct. Overkill maybe 🤷‍♂️

            Thank you for the link 🤘I’m gonna be updating this article soon with a roundup of different actions like this and will be sure to include it.

          1. Robert Avatar

            Oooh, nice. this releases action looks good. I’ll be including it in an updated version of this post soon 🙏

          2. Anh Tran Avatar

            It would be cool if the Github Action can handle build steps, including installing Composer & NPM dependencies and built JS/CSS files.

            1. Robert Avatar

              I’m working on an updated version of this article that showcases some actions other devs are using, and a new one I’m working on for my projects.

          1. Robert Avatar

            Automate the automation, I like it 🔥💯 Gonna review your post and link it in an updated version of this post.

        Leave a Reply

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