Use WordPress Path and URL Functions — Never Hardcode
Impact: MEDIUM (prevents broken paths across environments, subdirectory installs, and multisite configurations)
WordPress can be installed in a subdirectory, with a custom wp-content directory, or as a multisite network. Hardcoded URLs and filesystem paths break in all of these configurations and when moving between local, staging, and production environments.
Incorrect (hardcoded paths and URLs):
// ❌ Hardcoded domain — breaks on staging, local dev, and domain changes$logo = 'https://example.com/wp-content/themes/my-theme/images/logo.png';$ajax = 'https://example.com/wp-admin/admin-ajax.php';$home = 'https://example.com/';// ❌ Hardcoded filesystem path — breaks on different serversrequire_once '/var/www/html/wp-content/plugins/my-plugin/includes/helpers.php';$upload_path = '/var/www/html/wp-content/uploads/';// ❌ Assuming wp-content is in the default location$plugin_url = get_site_url() . '/wp-content/plugins/my-plugin/assets/style.css';// Breaks if WP_CONTENT_DIR is customized