Creating a WordPress plugin ZIP file makes it easy to share, install, or back up your plugin. Instead of manually copying files into the plugins folder, a ZIP package lets anyone upload the plugin directly through the WordPress dashboard.
Keep in mind
- The file format must be ZIP. WordPress does not support other archival formats.
- The ZIP file must contain a single root folder that has the same name as the plugin. This folder must contain the plugin files.
Recommended file structure
The following structure ensures your plugin adheres to WordPress best practices, ensuring your plugin is easy to install, maintain and extend.
1. Root Directory
The root directory of your plugin should contain:
plugin-name.php
: Your main plugin file with a header containing metadatauninstall.php
Code to uninstall the plugin (optional).readme.txt
Details about the plugin (optional)
2. Subdirectories
You can organize subdirectories any way you wish, but the following is common:
/assets/
: Store images, icons, and other media/includes/
: Help functions and classes used in PHP code/languages/
: Translation files (e.g.,.mo
and.po
files)./public/
: Files used in the front-end (e.g., CSS, JS, templates).
3. Example Structure
Here’s an example of a well-organized plugin ZIP file structure:
plugin-name/
├── plugin-name.php
├── uninstall.php
├── readme.txt
├── assets/
│ ├── banner-772x250.png
│ ├── icon-128x128.png
├── includes/
│ ├── class-plugin-name.php
│ ├── helper-functions.php
├── languages/
│ ├── plugin-name-en_US.mo
│ ├── plugin-name-en_US.po
├── admin/
│ ├── admin-menu.php
│ ├── admin-styles.css
├── public/
│ ├── public-scripts.js
│ ├── public-styles.css
4. Zipping the Plugin
When creating the ZIP file, your plugin folder should be in the root of the ZIP file. Your ZIP should only have that one folder in its root.
Instructions for Windows
- Open Explorer and navigate to your \wp-content\plugins\ folder
If you are building the plugin outside of WordPress, then navigate to the folder containing your custom plugin folder.
- Right-click your plugin folder and click Sent to > Compressed (zipped) folder
If you highlight and compress the folder in this way, the ZIP file will be packaged properly for WordPress.
- Confirm the ZIP is packaged correctly
Navigate into your ZIP file. You should see a single folder that has the same name as your plugin. Navigate into that folder as well. You should see your plugin files.
Instructions for PowerShell
In PowerShell, you can use the Compress-Archive cmdlet to create a ZIP file. You specify the path to the plugin folder and path to the output ZIP file as follows:
$pluginFolder = "C:\path\to\wordpress\wp-content\plugins\my-plugin"
$zipDestination = "C:\path\to\my-plugin.zip"
Compress-Archive -Path $pluginFolder -DestinationPath $zipDestination -Force
In this example, the Path
parameter specifies a folder. This is important because WordPress expects the ZIP file to contain a single folder with the plugin files. The Force
parameter tells PowerShell to overwrite the ZIP file if it exists. You can remove this parameter to cause an error if it exists.
Leave a Reply