WordPress Coding Standards in VSCode for Windows

This took me ages to get my head around in order to setup WordPress coding standards in VSCode for Windows.  Even using the great plugin Intelephense it doesn’t allow WordPress coding conventions which differ to PSR12.  I’ll outline the steps below to get this working in Windows.

  1. Install and download the Composer-Setp.exe
  2. Install PHP CodeSniffer (PHPCS) globally so it’s available for all projects.
  3. Composer will be installed under your roaming Windows profile.  Create a directory called “standards” in the following location.
  4. Using Git pull the latest version of the WordPress Coding Standards into this directory
  5. Add the WordPress Coding Standards to the PHPCS installed paths.  This will make it available to be used by the code sniffer and beautifier.
  6. You can confirm that the WordPress coding standard has been added by running the following command.
  7. Open VSCode and download these two extensions phpcs (code sniffing) and phpcbf (code beautifying).
  8. Add the following configuration to the settings.json file in VSCode.

    I actually prefer to switch off formatting on save and use hot keys (ALT + SHIFT + F ) instead to format.
  9. Restart VS Code to ensure changes have been recognised.

Leave a Reply

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