◦ Comprehensive security
◦ 24/7 support
WordPress Guide → Development → Coding Standards
WordPress coding standards: a beginner’s guide
If you’re building themes, plugins, or contributing to WordPress core, there’s one rule you can’t skip: follow the coding standards. These guidelines aren’t just about aesthetics—they’re about writing consistent, secure, and maintainable code that works across the entire WordPress ecosystem.
Whether you’re just starting out or want to improve your skills, here’s everything you need to know to start writing compliant code today.
Get fast, reliable hosting for WordPress
Power your site with the industry’s fastest, most optimized WordPress hosting
What are WordPress coding standards?
WordPress coding standards are a set of rules that define how your code should be written and formatted. They cover PHP, HTML, CSS, and JavaScript—ensuring that WordPress projects maintain a consistent structure and style.
These standards help developers work together more efficiently, avoid common errors, and build software that integrates smoothly with WordPress core and other plugins or themes.
Why follow WordPress coding standards?
Even if you’re working solo, sticking to coding standards has real benefits:
- Readability: Clean code is easier to read, debug, and maintain—especially when you return to it months later.
- Collaboration: Other developers will find your work easier to understand and contribute to.
- Compatibility: WordPress has certain expectations about how plugins and themes should behave. Standards help ensure your code plays nice.
- Security: Proper escaping and sanitization practices are baked into the standards, reducing vulnerabilities.
- Approval chances: Following standards is mandatory for submitting plugins or themes to the WordPress.org repository.
Where to find the official standards
WordPress maintains separate standards for each major language:
Each section is part of the official WordPress Developer Handbook, which is worth bookmarking if you’re doing any kind of development work.
Key elements of the PHP coding standards
PHP is the backbone of WordPress, so the PHP standards are the most detailed. Here are the main takeaways for beginners:
- Indentation: Use tabs (not spaces) for indentation.
- Braces: Opening braces go on the same line as the control structure.
- Yoda conditions: Always write conditions like if ( ‘value’ === $variable ) instead of $variable === ‘value’.
- Function and variable names: Use lowercase letters and underscores (snake_case).
- Sanitization: Always sanitize user input before saving it to the database.
- Escaping: Escape output using functions like esc_html() and esc_attr() before displaying it in the browser.
CSS and HTML standards: keeping it clean and accessible
CSS and HTML standards focus on clarity, accessibility, and performance.
- Tabs over spaces: Just like PHP, use tabs for indentation.
- Comments: Use clear and consistent comment styles to explain code sections.
- Class names: Keep them readable and descriptive—avoid cryptic abbreviations.
- Avoid inline styles: Always use external stylesheets.
- Accessibility: Use semantic HTML, label elements clearly, and avoid practices that hinder screen readers.
JavaScript standards: writing cleaner scripts
JavaScript is key for interactive WordPress features. WordPress coding standards ensure your scripts don’t conflict with others.
- Braces and indentation: Stick to tab-based indentation and always use braces, even for single-line if statements.
- Variable naming: Use camelCase for variables and functions.
- Avoid globals: Wrap your scripts in closures or use WordPress hooks.
- jQuery use: If you use jQuery, use jQuery instead of the $ shortcut to avoid conflicts.
Tools to help enforce WordPress coding standards
You don’t have to memorize every rule. There are tools that help enforce standards automatically:
- PHP_CodeSniffer + WordPress Coding Standards ruleset: This combo scans your PHP files and flags any violations.
- ESLint: A popular tool for JavaScript linting. Configure it with WordPress rules or presets.
- Stylelint: For CSS. Catch formatting issues before they become a problem.
- Code editor extensions: IDEs like PHPStorm or VS Code have WordPress-specific extensions that highlight issues in real time.
How to start writing compliant code
Here’s how to make standards part of your workflow from day one:
- Install a code sniffer for PHP and set up linters for JS/CSS.
- Use starter themes or frameworks like Underscores or the WordPress Plugin Boilerplate. These are already formatted correctly.
- Practice good habits: Even if you don’t get every rule right at first, consistent effort makes improvement easy.
- Test early and often: Don’t wait until launch to run your code through sniffer tools.
Act like you been there: Common newbie mistakes to avoid
Avoiding these pitfalls will make your development smoother and your submissions more likely to be approved:
- Mixing tabs and spaces: Stick to tabs—WordPress is strict about this.
- Skipping sanitization/escaping: Never trust user input. Sanitize on input, escape on output.
- Inconsistent naming: Stick with snake_case for PHP, camelCase for JavaScript.
- Missing translation functions: Always wrap user-facing text in functions like __() or _e() to support localization.
- Not enqueueing scripts: Avoid direct script inclusion. Always use wp_enqueue_script() and wp_enqueue_style().
Next steps for learning WordPress coding standards
Following WordPress coding standards is one of the easiest ways to write better, more professional code. It also sets you up for long-term success whether you’re freelancing, collaborating, or contributing to WordPress core.
The best way to improve is to get hands-on. Start by building or refactoring a small plugin or theme.
Ready to upgrade your WordPress experience? Professional hosting improves speeds, security, and reliability for a website and a brand that people find engaging and trustworthy.
Don’t want to deal with server management and maintenance? Our fully managed hosting for WordPress is the best in the industry. Our team are not only server IT experts, but WordPress hosting experts as well. Your server couldn’t be in better hands.
Click through below to explore all of our hosting for WordPress options, or chat with a WordPress expert right now to get answers and advice.
Additional resources
What is managed WordPress hosting? →
Get details and decide if managed WordPress hosting is right for you.
How to push specific pages in WordPress →
Easily push specific pages from staging to live in WordPress without affecting the entire site.
A complete guide to WordPress shortcodes →
Shortcodes make life easier. Learn how to get started!