wp plugin path
Overview
Retrieve the absolute path to a plugin's directory or main file on the filesystem. Useful for shell scripts that need to reference plugin files directly — for editing, copying, symlinking, or inspection.
What It Does
wp plugin path resolves and prints the absolute filesystem path to a plugin's directory (or main file if --file is used). It reads from the active WordPress installation's plugin directory (wp-content/plugins/).
Syntax
wp plugin path [<plugin>] [--dir] [--file]
Arguments & Options
| Argument / Flag | Description |
|---|---|
PLUGIN | Plugin slug (omit to get the plugins root directory) |
--dir | Return the plugin's directory path (default behavior) |
--file | Return the path to the plugin's main PHP file |
Basic Usage
Get the plugins directory (no slug)
wp plugin path
Output:
/var/www/html/wp-content/plugins
Get a specific plugin's directory
wp plugin path woocommerce
Output:
/var/www/html/wp-content/plugins/woocommerce
Get the main plugin PHP file path
wp plugin path woocommerce --file
Output:
/var/www/html/wp-content/plugins/woocommerce/woocommerce.php
Real-World Scenarios
Scenario 1: Read a plugin's version header directly from the file
PLUGIN_FILE=$(wp plugin path woocommerce --file)
grep "^.*Version:" "${PLUGIN_FILE}" | head -1
Scenario 2: Symlink a development plugin instead of copying
PLUGIN_DIR=$(wp plugin path)
ln -sf /home/dev/projects/my-custom-plugin "${PLUGIN_DIR}/my-custom-plugin"
wp plugin activate my-custom-plugin
Scenario 3: Check plugin directory contents for suspicious files
PLUGIN_DIR=$(wp plugin path woocommerce)
echo "Checking ${PLUGIN_DIR} for non-standard PHP files..."
find "${PLUGIN_DIR}" -name "*.php" -newer "${PLUGIN_DIR}/woocommerce.php" -not -path "*/node_modules/*"
Scenario 4: Backup a specific plugin's directory before update
PLUGIN_DIR=$(wp plugin path woocommerce)
PLUGIN_VERSION=$(wp plugin get woocommerce --field=version)
tar -czf "/var/backups/plugins/woocommerce_v${PLUGIN_VERSION}_$(date +%Y%m%d).tar.gz" "${PLUGIN_DIR}"
echo "Backup created ✅"
Scenario 5: Navigate to plugin directory in a script
PLUGIN_PATH=$(wp plugin path woocommerce)
echo "Working in: ${PLUGIN_PATH}"
# Count PHP files
PHP_COUNT=$(find "${PLUGIN_PATH}" -name "*.php" | wc -l)
echo "Plugin PHP file count: ${PHP_COUNT}"
# Check for composer.json
if [ -f "${PLUGIN_PATH}/composer.json" ]; then
echo "Plugin uses Composer"
fi
Common Use Cases
| Use Case | Command |
|---|---|
| Navigate to plugins root | cd $(wp plugin path) |
| Edit a plugin file | nano $(wp plugin path woocommerce --file) |
| Backup plugin before update | tar -czf backup.tar.gz $(wp plugin path woocommerce) |
| Symlink development plugin | ln -sf /dev/my-plugin $(wp plugin path)/my-plugin |
| Find main plugin file | wp plugin path woocommerce --file |
Best Practices
- Use in scripts instead of hardcoding paths — the plugins directory can vary across hosting environments.
- Combine with
wp plugin get --field=versionfor filename versioning in backups. - Use
--filewhen you need to inspect or source the plugin header directly. - Remember custom plugin directories — if
WP_PLUGIN_DIRis defined inwp-config.php, this command respects it.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Error: Plugin not found | Wrong slug | Use wp plugin list --field=name to find the correct slug |
| Path is unexpected | Custom WP_PLUGIN_DIR in config | Check wp config get WP_PLUGIN_DIR |
| Path not accessible | Permission issue | Check file ownership |
Quick Reference
wp plugin path # Plugins root directory
wp plugin path woocommerce # Plugin directory
wp plugin path woocommerce --file # Main plugin PHP file
cd $(wp plugin path woocommerce) # Navigate to plugin
Next Steps
wp plugin get— get plugin metadata without reading files directly.wp plugin list— inventory all installed plugins.wp plugin install— install from zip at a custom path.