Skip to main content

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 / FlagDescription
PLUGINPlugin slug (omit to get the plugins root directory)
--dirReturn the plugin's directory path (default behavior)
--fileReturn 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
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 CaseCommand
Navigate to plugins rootcd $(wp plugin path)
Edit a plugin filenano $(wp plugin path woocommerce --file)
Backup plugin before updatetar -czf backup.tar.gz $(wp plugin path woocommerce)
Symlink development pluginln -sf /dev/my-plugin $(wp plugin path)/my-plugin
Find main plugin filewp plugin path woocommerce --file

Best Practices

  1. Use in scripts instead of hardcoding paths — the plugins directory can vary across hosting environments.
  2. Combine with wp plugin get --field=version for filename versioning in backups.
  3. Use --file when you need to inspect or source the plugin header directly.
  4. Remember custom plugin directories — if WP_PLUGIN_DIR is defined in wp-config.php, this command respects it.

Troubleshooting

ProblemCauseFix
Error: Plugin not foundWrong slugUse wp plugin list --field=name to find the correct slug
Path is unexpectedCustom WP_PLUGIN_DIR in configCheck wp config get WP_PLUGIN_DIR
Path not accessiblePermission issueCheck 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