Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Setup & site building · Guide

How to Use WordPress in VS Code: A Beginner's Guide

How to Use WordPress in VS Code: A Beginner's Guide

Short answer

Run WordPress on your computer with a tool such as Local or wp-env, then open the site folder in VS Code. Add a PHP extension for code hints, edit your theme or plugin files, and refresh the browser to see changes. Use the built-in terminal for WP-CLI.

Key takeaways

  • VS Code edits files but needs a local server to run WordPress.
  • Open only your theme or plugin folder for focused work.
  • Intelephense adds PHP autocomplete and error hints.
  • Xdebug and WP_DEBUG make bugs easier to find.
  • Edit locally and deploy instead of editing live files.

How do you use WordPress in VS Code?

Run a WordPress site on your computer, open its folder in VS Code, add a PHP extension for code hints, and edit theme or plugin files while the browser shows your changes.

VS Code is a free code editor from Microsoft. It does not run WordPress by itself, so you pair it with a local server tool that provides PHP, a database and a web server.

Once that pairing is in place, VS Code becomes your workshop. You write code, search files, run commands in the built-in terminal and track changes with Git, all in one window.

Part of the setupCommon choiceWhat it does
Local serverLocal, wp-env, DevKinsta, DockerRuns PHP, MySQL and WordPress
Code editorVS CodeEdits theme and plugin files
PHP language supportIntelephense extensionAutocomplete and error hints
DebuggerXdebug with PHP Debug extensionStep through code line by line
Command lineWP-CLI in the VS Code terminalManage WordPress from commands
Version controlGit (built into VS Code)Tracks and reverts changes

Step 1: Install VS Code and a local WordPress site

Download VS Code from the official site, then create a local WordPress site with a tool such as Local or wp-env so you have files to open and a site to preview.

VS Code installs on Windows, macOS and Linux from code.visualstudio.com. Pick the stable release unless you want early features.

For the local site, beginners usually start with Local because it needs no command line. Our guide on installing WordPress with Local covers that step by step.

Developers who already use Node.js often prefer wp-env. The official wp-env documentation shows how one command spins up WordPress in Docker.

If you want to compare all the options, read our guide to setting up a local WordPress development environment.

Step 2: Open the right folder in VS Code

In VS Code, choose File > Open Folder and select either the whole WordPress folder or just the theme or plugin folder you plan to work on.

With Local, right-click the site and choose Go to site folder. The WordPress files sit inside app/public.

Opening only your theme or plugin folder keeps the file list short and search results relevant. Opening the full install is better when you need to read core files to understand a function.

Avoid editing WordPress core files in wp-admin or wp-includes. Updates overwrite them, and changes there can break the site.

Step 3: Add PHP extensions for code hints

Install a PHP language extension such as Intelephense from the Extensions panel so VS Code can autocomplete functions, show parameter hints and flag errors.

VS Code has basic PHP support built in. Microsoft's PHP in Visual Studio Code guide explains what is included and which extensions add more.

Intelephense understands PHP well, but it does not know WordPress functions until it can see core files. If you only opened your theme folder, add the WordPress core path to the extension's include paths, or open the whole install.

Some developers also add WordPress-specific extensions that suggest hook names and snippets. Check the reviews and update dates in the Extensions panel before installing, since quality varies.

Step 4: Edit theme or plugin files and preview changes

Make your edits in VS Code, save the file, and refresh the local site in your browser to see the result straight away.

For theme work, create a child theme first. Then your changes survive when the parent theme updates.

Typical files you will edit include:

  • functions.php for hooks, filters and small features.
  • style.css or other stylesheets for design changes.
  • theme.json in block themes for colours, fonts and spacing.
  • Template files such as single.php or block templates in the templates folder.
  • Your plugin's main PHP file if you are building a plugin.

New to theme code? Our guide on how to code in WordPress explains where different kinds of code belong.

Step 5: Use the built-in terminal and WP-CLI

Open the terminal with Ctrl+` (backtick) and run WP-CLI commands to install plugins, create users, flush caches or run search-and-replace without leaving VS Code.

WP-CLI is the official command line tool for WordPress. Local includes a site shell that has WP-CLI ready, and wp-env lets you run it through its own commands.

A few commands you will use often:

  • wp plugin list to see installed plugins and their status.
  • wp theme activate name to switch themes.
  • wp cache flush to clear the object cache.
  • wp search-replace old new to update URLs in the database.

Running commands in the editor terminal keeps your workflow in one window. It also makes it easy to copy errors into your code.

Step 6: Debug PHP with Xdebug

Turn on Xdebug in your local tool, install the PHP Debug extension in VS Code, set a breakpoint and start listening, then load the page to pause code at that line.

Breakpoints let you inspect variables at a specific moment. That is far quicker than adding var_dump lines everywhere and deleting them later.

Local has an Xdebug toggle in each site's settings. Other setups need Xdebug configured in php.ini, as shown in the Xdebug documentation.

For simpler checks, switch on WP_DEBUG and WP_DEBUG_LOG in wp-config.php. Errors then go to wp-content/debug.log, which you can open in VS Code.

Step 7: Follow WordPress coding standards

Install PHP_CodeSniffer with the WordPress Coding Standards ruleset, then connect it to VS Code so the editor flags style problems as you type.

The WordPress PHP coding standards set rules for spacing, naming, escaping and more. Following them makes your code easier for others to read and review.

The ruleset also catches real security issues, such as output that is not escaped. That alone makes it worth setting up.

Formatter extensions can tidy code on save. Pick one that respects WordPress style, or you may end up fighting automatic reformatting.

Step 8: Track changes with Git

Open the Source Control panel, initialise a repository in your theme or plugin folder, and commit after each working change so you can roll back mistakes.

VS Code has Git built in. You see changed files, line-by-line differences and a commit box in the sidebar.

Push your repository to a service such as GitHub to keep a backup and share work. Many hosts can also deploy straight from a Git repository.

Which VS Code settings help with WordPress files?

A few small settings make WordPress work smoother: format on save, a tab size that matches WordPress style, and file associations for template files.

WordPress PHP standards use real tabs for indentation, not spaces. Set Editor: Insert Spaces to off for PHP files so your indentation matches.

Turn on Files: Trim Trailing Whitespace to keep diffs clean. Small whitespace changes otherwise clutter every Git commit.

If you work on block themes, VS Code can validate theme.json against its schema. Add the schema line at the top of the file and the editor suggests valid keys as you type.

Save these choices in a workspace settings file inside your project. Then every teammate who opens the folder gets the same behaviour.

Can you edit a live WordPress site from VS Code?

Yes, you can connect to a live server with an SFTP or Remote SSH extension and edit files directly, but it is risky and best kept for small, urgent fixes.

A typo in functions.php can take down a live site with a fatal error. Visitors see it immediately, and you may lose access to the dashboard.

The safer workflow is to edit locally, test, commit to Git and then deploy. If you must edit live, download a backup of the file first.

If a live edit breaks the site, our guide on adding code to WordPress safely covers safer places to put snippets.

Why is your local site not loading in VS Code?

VS Code does not serve websites, so if the site will not load, the problem is almost always the local server tool rather than the editor.

Check that the site is started in Local or that wp-env is running. Then confirm the URL in your browser matches the site's domain.

Port conflicts are a common cause, especially when another app uses port 80 or 8888. Our guide on WordPress not working on localhost lists the usual fixes.

Frequently asked questions

Is VS Code good for WordPress development?

Yes. VS Code is free, fast and has strong PHP, JavaScript and CSS support through extensions. It also has Git and a terminal built in, which covers most of what WordPress theme and plugin developers need day to day.

Do I need XAMPP to use WordPress with VS Code?

Not necessarily. XAMPP is one way to run PHP and MySQL locally, but tools like Local, DevKinsta and wp-env are easier for WordPress. Any of them works with VS Code because the editor just opens the files.

Can VS Code run PHP for WordPress?

VS Code can run PHP scripts if PHP is installed on your computer, but WordPress also needs a web server and a database. That is why you pair the editor with a local development tool that provides the full stack.

Which VS Code extensions are best for WordPress?

A PHP language extension such as Intelephense, PHP Debug for Xdebug, a PHP_CodeSniffer integration for WordPress Coding Standards, and optionally an SFTP extension. Check update dates and reviews before installing any extension.

Can I build Gutenberg blocks in VS Code?

Yes. Block development uses JavaScript and React, which VS Code supports out of the box. Use the official create-block tool to scaffold a block plugin, then open the folder in VS Code and run the build commands in the terminal.

Sources

  1. PHP in Visual Studio Code Visual Studio Code Docs
  2. @wordpress/env WordPress Developer Resources
  3. PHP Coding Standards WordPress Developer Resources
  4. WP-CLI WP-CLI
  5. Xdebug Documentation Xdebug

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

Written and checked byWPLegible Editorial Team Independent WordPress reviews and guides

Researched from the primary sources listed above and checked against our editorial rules before publishing.