Developer · Guide
How to Code in WordPress: A Practical Starting Guide

Short answer
To code in WordPress, learn the basics of PHP, HTML, CSS and JavaScript, set up a local WordPress install, and write your code in a small custom plugin or a child theme rather than editing core or theme files. Use hooks, actions and filters, to change how WordPress behaves, and follow the official coding standards.
Key takeaways
- WordPress runs on PHP and MySQL on the server, with HTML, CSS and JavaScript in the browser.
- Never edit WordPress core or a parent theme directly; updates will overwrite your changes.
- Put site features in a custom plugin and design changes in a child theme or block theme.
- Hooks are the heart of WordPress development: actions run your code, filters change data.
- Practise on a local or Playground install, not on a live site.
Which languages do you need to code in WordPress?
WordPress uses PHP for server logic, HTML for structure, CSS for design, JavaScript for interactive features and the block editor, and SQL through its database layer.
You do not need to master all of them at once. Pick the one that matches what you want to change:
| Goal | Language to learn first |
|---|---|
| Change colors, spacing, fonts | CSS, plus theme.json for block themes |
| Add a feature or change behavior | PHP |
| Build custom blocks or editor tools | JavaScript and React |
| Change page structure | HTML and block markup |
| Custom queries and reports | PHP with the WP_Query class |
The PHP manual and MDN Web Docs are the standard references for the languages themselves.
Where should you write code in WordPress?
Write code in a custom plugin for features and in a child theme or your own theme for design, never in WordPress core files or a theme you did not build.
WordPress core, parent themes and plugins from other people are replaced on every update. Any code you add there disappears without warning.
Use this rule of thumb:
- Custom plugin: anything that should keep working if you change themes, such as custom post types, shortcodes or integrations
- Child theme: template and style changes for a classic theme
- Block theme files or Site Editor: templates, patterns and theme.json changes
- Code snippets plugin: small one-off snippets if you do not want to manage files
Our guide to child themes explains how they inherit from a parent theme safely.
How do you set up a place to practise?
Use a local WordPress install or WordPress Playground in the browser, so mistakes cannot break a live site.
WordPress Playground runs a full WordPress site in your browser with nothing to install. It is ideal for testing a snippet in seconds.
For real projects, set up a local environment on your computer with tools such as Local, DDEV or wp-env. Our guide to setting up a local WordPress development environment compares them.
Add a code editor such as VS Code and turn on debugging in wp-config.php. Seeing errors as you work saves hours of guessing.
How do hooks work in WordPress?
Hooks let your code run at specific moments or change data without editing core files: actions run code at an event, and filters modify a value and return it.
This is the most important idea in WordPress development. Almost every customisation uses a hook.
An action example, adding text to the footer:
add_action( 'wp_footer', function () {
echo '<p class="note">Thanks for visiting.</p>';
} );
A filter example, changing the excerpt length:
add_filter( 'excerpt_length', function ( $length ) {
return 30;
} );
The Plugin Handbook section on hooks lists how they work and how to find the right one. The Code Reference documents every hook WordPress provides.
How do you write your first WordPress plugin?
Create a folder in wp-content/plugins, add a PHP file with a plugin header comment, put your hooked code below it and activate it from the Plugins screen.
A complete, minimal plugin looks like this:
<?php
/**
* Plugin Name: My Site Tweaks
* Description: Small custom features for this site.
* Version: 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_filter( 'excerpt_length', fn() => 30 );
Save it as wp-content/plugins/my-site-tweaks/my-site-tweaks.php. The ABSPATH check stops the file from running if someone opens it directly in a browser.
The official Plugin Handbook covers headers, activation hooks, settings pages and security in depth.
How do you change the design with code?
For block themes, change design tokens in theme.json and templates in HTML files; for classic themes, add CSS and PHP templates in a child theme.
Modern block themes keep colors, fonts, spacing and layout widths in theme.json. Changing a value there updates the whole site and the editor at the same time. Our guide on using theme.json shows the structure.
For small style changes, you can add CSS in the Site Editor's Additional CSS panel. Move larger amounts into your theme's stylesheet so they are easier to manage.
How do you build custom features like post types and blocks?
Register custom post types and taxonomies with PHP in a plugin, and build custom blocks with JavaScript, React and block.json.
Custom post types turn WordPress into more than a blog, for example for events, recipes or properties. Our guide to creating a custom post type walks through register_post_type.
Blocks are built with modern JavaScript and a build step. The create-block tool generates a working starter plugin. See our guide to creating a custom block for the steps.
When your feature needs to talk to JavaScript or another app, use the REST API. Our guide on creating a custom REST API endpoint shows how.
How do you debug WordPress code?
Turn on WP_DEBUG and the debug log on your development site, read the exact error and line number, and use a tool like Query Monitor to inspect hooks, queries and PHP errors.
Add these lines to wp-config.php on a local or staging site only:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
Errors then go to wp-content/debug.log instead of the screen. The debugging guide explains each constant and a few more, such as SCRIPT_DEBUG for unminified scripts.
Never leave debug display on for a live site. Error messages can reveal file paths and other details an attacker could use.
The free Query Monitor plugin adds a panel to the admin bar. It shows slow database queries, which hooks ran, which template loaded and any PHP notices, which makes it the fastest way to understand what your code is doing.
When something goes wrong, change one thing at a time and reload. Small steps make it obvious which line caused the problem.
How do you use the command line with WordPress?
Use WP-CLI, the official command-line tool, to install plugins, run database tasks, create test content and scaffold code much faster than through the dashboard.
Most good hosts and every common local tool include WP-CLI. A few commands you will use often:
- wp plugin list, to see installed plugins and their status
- wp scaffold plugin, to generate a plugin skeleton with tests
- wp post generate, to create dummy posts for testing
- wp search-replace, to change URLs in the database safely
- wp cron event list, to check scheduled tasks
Learning a handful of commands pays off quickly, especially when you manage more than one site.
Which rules should your WordPress code follow?
Follow the WordPress Coding Standards, escape all output, sanitize and validate all input, check permissions and use nonces for forms and actions.
Most security problems in WordPress plugins come from skipping these steps. The core functions make them easy:
- Sanitize input: sanitize_text_field(), absint(), sanitize_email()
- Escape output: esc_html(), esc_attr(), esc_url()
- Check permissions: current_user_can() before any admin action
- Verify intent: wp_nonce_field() and check_admin_referer() on forms
- Query safely: use $wpdb->prepare() for custom SQL
The WordPress Coding Standards explain naming, formatting and documentation rules. Tools like PHP_CodeSniffer with the WordPress ruleset check them automatically.
Prefix your function names, or use a namespace, so they do not clash with other plugins. A function called get_settings() in your plugin will crash the site the day another plugin defines the same name, while myprefix_get_settings() will not.
Also keep your code under version control with Git from the first day. It lets you undo mistakes, see what changed and deploy the same code to staging and live sites.
What is the best way to keep learning?
Build small real projects, read core and plugin code, and use the free developer courses on Learn WordPress as a structured path.
Good first projects include a shortcode that shows the current year, a custom admin notice, a simple custom post type, and a settings page with one option.
When a function confuses you, open its page in the Code Reference and read the source. WordPress's own code is the best example of how its APIs are meant to be used.
Learn WordPress offers free developer courses and workshops at learn.wordpress.org, from beginner PHP to block development.
Frequently asked questions
Do I need to know PHP to use WordPress?
No. You can build and run a WordPress site without code. PHP becomes useful when you want custom features, changes to how WordPress behaves, or your own plugins and classic themes.
Where do I put custom code in WordPress?
Put feature code in a small custom plugin and design code in a child theme or your own theme. A code snippets plugin also works for short snippets. Never edit WordPress core or a parent theme directly.
How long does it take to learn WordPress development?
If you already know some HTML and CSS, you can write simple plugins with hooks within a few weeks of practice. Building custom blocks and complex plugins takes months, because it also needs modern JavaScript and React.
Is editing functions.php a good idea?
It works for small changes in your own child theme, but the code stops running if you switch themes. Site features that should survive a theme change belong in a custom plugin instead.
Which code editor is best for WordPress?
Any good code editor works. VS Code and PhpStorm are popular because they support PHP debugging, WordPress coding standards checks and autocomplete for WordPress functions through extensions.
Sources
- Plugin Handbook WordPress Developer Resources
- Hooks WordPress Developer Resources
- WordPress Coding Standards WordPress Developer Resources
- PHP Manual PHP.net
- WordPress Playground WordPress.org
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.
Thanks — we review requests within 3 business days.
Related guides
About the editors
Researched from the primary sources listed above and checked against our editorial rules before publishing.


