Skip to content

Set Up Visual Studio Code for WordPress Development

I figured I’d try installing PHP_CodeSniffer and the WordPress Coding Standards and found that after running composer create-project wp-coding-standards/wpcs ---no-dev and (manually) adding ~/wpcs/vendor/bin to my PATH, I needed to also run phpcs ---config-set installed_paths ~/wpcs for PHP_CodeSniffer to pick up the WordPress standards.

After that, it’s really just installing the phpcs extension for Visual Studio Code—File > Preferences > Extensions, then search phpcs—and adding "phpcs.standard": "WordPress" to the (JSON) settings.

I also quickly found out the default WordPress rules don’t like ‘incorrectly named’ classes inside a main plugin file—something I sometimes rely on to keep things a bit more organized—so I soon set up a custom phpcs.xml that tells phpcs to use a slightly modified ruleset and added "phpcs.standard": "phpcs.xml" to my workspace settings.json—it seems without, phpcs sometimes ignores it, though chances are I’m still doing something wrong.