{"id":37161,"date":"2020-09-29T07:39:00","date_gmt":"2020-09-29T12:39:00","guid":{"rendered":"https:\/\/wpengine.com\/?post_type=resource&#038;p=37161"},"modified":"2024-01-09T11:22:36","modified_gmt":"2024-01-09T17:22:36","slug":"developer-best-practices","status":"publish","type":"resource","link":"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/","title":{"rendered":"WordPress Best Practices for Developers"},"content":{"rendered":"\n<p><span style=\"font-weight: 400\">This article explains the importance of following WordPress Best Practices as a developer. <\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400\">Learn how to write and structure your code properly, test it against WordPress Core standards, and best practices for site creation and management in our developer starter guide. Most importantly, gain tangible insights for how to implement these strategies and practices on your own websites. <\/span><\/p>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">Best WordPress Practices for Beginning Developers<\/h2>\n\n\n\n<p><span style=\"font-weight: 400\">If you are new to the WordPress world as a developer, there are some best practices that will make your life easier. Below we cover some of the \u201cneed to know\u201d practices as you embark on this new journey. Adhering to these best practices will help you later down the line as you build upon your WordPress development skills. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Use WordPress Site\/Home URLs<\/h3>\n\n\n\n<p><span style=\"font-weight: 400\">In WordPress, you must configure which domain should be used by your website using a <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/site_url\/\" target=\"_blank\" rel=\"noreferrer noopener\">site_url()<\/a> and <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/home_url\/\" target=\"_blank\" rel=\"noreferrer noopener\">home_url()<\/a>. While WordPress has a <\/span><i><span style=\"font-weight: 400\">wp-config.php<\/span><\/i><span style=\"font-weight: 400\"> file where you can hardcode your website\u2019s URL, it is way easier to use the native way. In your WordPress Admin Dashboard (\/wp-admin\/) you can navigate to <\/span><i><span style=\"font-weight: 400\">Settings &gt; General<\/span><\/i><span style=\"font-weight: 400\"> and edit your WordPress Address (URL) and Site Address (URL) fields. These fields should match, and should begin with <\/span><i><span style=\"font-weight: 400\">http:\/\/<\/span><\/i><span style=\"font-weight: 400\"> or <\/span><i><span style=\"font-weight: 400\">https:\/\/<\/span><\/i><span style=\"font-weight: 400\">.<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1994\" height=\"328\" src=\"https:\/\/wpengine.com\/wp-content\/uploads\/2018\/04\/site_url_home_url_wordpress.png\" alt=\"WordPress Address (URL) settings within the admin dashboard. WordPress Best Practices for Developers\" class=\"wp-image-37167\" srcset=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/site_url_home_url_wordpress.png 1994w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/site_url_home_url_wordpress-300x49.png 300w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/site_url_home_url_wordpress-768x126.png 768w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/site_url_home_url_wordpress-1024x168.png 1024w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/site_url_home_url_wordpress-1500x247.png 1500w\" sizes=\"auto, (max-width: 1994px) 100vw, 1994px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Adhere to WordPress Coding Standards<\/h3>\n\n\n\n<p><span style=\"font-weight: 400\">The WordPress community is a rich community of developers who have worked tirelessly to make it the success it is today. These developers have learned through their own trial and error, and have put together coding standards to ensure the best success and security. If you are creating a plugin or theme via PHP, check out the <a href=\"https:\/\/make.wordpress.org\/core\/handbook\/best-practices\/coding-standards\/php\/\" target=\"_blank\" rel=\"noreferrer noopener\">PHP Coding Standards for WordPress<\/a> to get started. <\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400\">And if you plan on developing with JavaScript, you can look to the <a href=\"https:\/\/make.wordpress.org\/core\/handbook\/best-practices\/coding-standards\/javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">JavaScript Coding Standards<\/a> for WordPress. Doing so will set you up for success later on, as you hone your WordPress skills further.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Choose Plugin and Theme Developers Who Care<\/h3>\n\n\n\n<p><span style=\"font-weight: 400\">When setting up your site, you will undoubtedly need to choose which 3rd party plugins and theme to use. It is best to choose a plugin or theme that is updated frequently and has high satisfaction ratings. Frequent updates mean the developer is interested in keeping their work compatible with the latest versions of WordPress. It also means they are more likely to help if you encounter conflicts with their code!<\/span> <\/p>\n\n\n\n<p>Use <a href=\"https:\/\/wpengine.com\/support\/smart-plugin-manager\/\" target=\"_blank\" rel=\"noreferrer noopener\">WP Engine\u2019s Smart Plugin Manager<\/a> to keep your environments secure and automatically updated.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1064\" height=\"588\" src=\"https:\/\/wpengine.com\/wp-content\/uploads\/2018\/04\/jetpack_plugin_ratings.png\" alt=\"Jetpack for WordPress plugin. WordPress Best Practices for Developers\" class=\"wp-image-37166\" srcset=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/jetpack_plugin_ratings.png 1064w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/jetpack_plugin_ratings-300x166.png 300w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/jetpack_plugin_ratings-768x424.png 768w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/jetpack_plugin_ratings-1024x566.png 1024w\" sizes=\"auto, (max-width: 1064px) 100vw, 1064px\" \/><\/figure>\n\n\n\n<p><span style=\"font-weight: 400\">Looking at the user base is a good indicator for success as well. If there are thousands of active installations of the plugin or theme, it\u2019s more likely that people have also used it successfully. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Always Be Updating<\/h3>\n\n\n\n<p><span style=\"font-weight: 400\">WordPress typically releases updates many times per year. Oftentimes, between major updates there will be maintenance\/security updates as well. Not to mention, good plugin and theme developers will also release improvements and maintenance\/security updates often. These updates are important to the integrity of your site! Be sure to login at least once per month to check for any available updates and run them. <\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400\">If you want to play it safe, it\u2019s best to create a development or staging instance for testing first. Then you can run the updates in this testing environment first, to ensure there are no issues.<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1358\" height=\"310\" src=\"https:\/\/wpengine.com\/wp-content\/uploads\/2018\/04\/dashboard_wordpress_updates.png\" alt=\"WordPress version in the admin dashboard. WordPress Best Practices for Developers\" class=\"wp-image-37165\" srcset=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/dashboard_wordpress_updates.png 1358w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/dashboard_wordpress_updates-300x68.png 300w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/dashboard_wordpress_updates-768x175.png 768w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/dashboard_wordpress_updates-1024x234.png 1024w\" sizes=\"auto, (max-width: 1358px) 100vw, 1358px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Stay Secure<\/h3>\n\n\n\n<p><span style=\"font-weight: 400\">It\u2019s best practice to take some preventative security measures on your website(s) as well. There are many users, bots, and services on the internet that might attempt to access your site in a way you don\u2019t want. Unwanted access could mean spam login attempts, spam comments, or even malicious bots that generate tons of traffic in an attempt to take your website down. There are a few simple ways to prevent security issues:<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><b>Pick a secure Username and Password.<\/b><span style=\"font-weight: 400\"> Don\u2019t use easy-to-guess Usernames like \u201c<\/span><i><span style=\"font-weight: 400\">Admin<\/span><\/i><span style=\"font-weight: 400\">,\u201d and ensure your password is over 10 characters and a mix of numbers, letters, and special characters. <\/span><\/li>\n\n\n\n<li><b>Use a Captcha or other filtering method on any submittable form.<\/b><span style=\"font-weight: 400\"> This helps ensure a bot or spammer can\u2019t easily send repeated requests to these forms, which is one of the most common spam methods. <\/span><\/li>\n\n\n\n<li><b>Use a plugin or service for additional security.<\/b><span style=\"font-weight: 400\"> There are comprehensive security plugins available like <a href=\"https:\/\/wordpress.org\/plugins\/better-wp-security\/\" target=\"_blank\" rel=\"noreferrer noopener\">Solid Security<\/a> or <a href=\"https:\/\/wordpress.org\/plugins\/all-in-one-wp-security-and-firewall\/\" target=\"_blank\" rel=\"noreferrer noopener\">All-In-One Security &amp; Firewall<\/a> which cover your website from multiple vectors. These plugins keep track of fake login attempts, allow blacklisting and whitelisting, log user activity, and block brute force attackers. You can also configure a firewall like <a href=\"https:\/\/sucuri.net\/website-firewall\/\" target=\"_blank\" rel=\"noreferrer noopener\">Sucuri WAF<\/a> or <a href=\"https:\/\/www.cloudflare.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Cloudflare<\/a> to mitigate risk of a DDoS attack and control your website\u2019s traffic in a more granular way. <\/span><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for WordPress Site Builders<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1242\" height=\"442\" src=\"https:\/\/wpengine.com\/wp-content\/uploads\/2018\/04\/site_builders_image.png\" alt=\"tools on a table. WordPress Best Practices for Developers\" class=\"wp-image-37170\" srcset=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/site_builders_image.png 1242w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/site_builders_image-300x107.png 300w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/site_builders_image-768x273.png 768w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/site_builders_image-1024x364.png 1024w\" sizes=\"auto, (max-width: 1242px) 100vw, 1242px\" \/><\/figure>\n\n\n\n<p><span style=\"font-weight: 400\">In addition to the general best practices for developers described above, there are some general rules for success for site builders. In this section we will explain a few rules of thumb when building a site with WordPress.<\/span><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><b>Firstly, if you didn\u2019t build or write it, don\u2019t touch it.<\/b><span style=\"font-weight: 400\"> This simply means you should leave WordPress Core files and 3rd-party plugins as-is. If you update the code of these assets you risk overwriting your custom code when you update it in the future. For instance, if I added some functions to a theme\u2019s functions.php file, the next time I update the theme I risk overwriting that file. Instead, I should create a \u201cchild theme\u201d to accomplish this.<\/span><\/li>\n\n\n\n<li><b>Add custom functions via a site-specific plugin<span style=\"font-weight: 400\">. While many guides will guide you in how to create a WordPress child theme, there aren\u2019t many tutorials for creating custom functionality through a plugin. A <a href=\"http:\/\/www.wpbeginner.com\/beginners-guide\/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin\/\" target=\"_blank\" rel=\"noreferrer noopener\">custom plugin<\/a> can be used to add specific code snippets to your WordPress site, and can be an easy way to add functionality you\u2019re looking for. For example, you could write a custom plugin to give you a custom post type with the attributes you need. Or you could add a plugin to add a new type of User Role. The benefit of adding these functions as a plugin rather than a theme is that it allows you to switch your active theme without losing the functionality. <\/span><\/b><\/li>\n\n\n\n<li><strong>Add custom functions via a child theme<\/strong><span style=\"font-weight: 400\"><strong>.<\/strong> Many times developers will choose to build upon an existing theme rather than building a whole theme as new. This allows the developer the freedom to customize the theme they like to their client, without doubling their workload. To do this, developers must install the original theme, then create a \u201c<a href=\"https:\/\/developer.wordpress.org\/themes\/advanced-topics\/child-themes\/\" target=\"_blank\" rel=\"noreferrer noopener\">child theme<\/a>\u201d version of it. In this way, they can ensure their custom code will not break when the original theme is updated. Creating a child theme is as simple as creating the child theme directory in your \/wp-content\/themes\/ folder, and adding a functions.php file and style.css file there via <a href=\"https:\/\/wpengine.com\/support\/sftp\/\" target=\"_blank\" rel=\"noreferrer noopener\">SFTP<\/a>. Use the Child Theme guide from WordPress for further instructions. <\/span><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Writing Code in WordPress<\/h2>\n\n\n\n<p><span style=\"font-weight: 400\">This section is exclusively for those developers who are writing code for WordPress. Below we will cover best practices when developing code for WordPress, including why it is beneficial. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Readability<\/h3>\n\n\n\n<p><span style=\"font-weight: 400\">When writing code for WordPress, remember that you aren\u2019t just writing code for yourself. Your code should be readable by any developer. That means adhering to normal spacing and grouping patterns. As WordPress says in their coding standards, <\/span><i><span style=\"font-weight: 400\">\u201cWhen in doubt, space it out.\u201d<\/span><\/i> <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Reliability<\/h3>\n\n\n\n<p><span style=\"font-weight: 400\">Beyond being easy to comprehend, your code should also adhere to WordPress standards, as well as your own team\u2019s standards for excellence. Reliable code is code that is structured consistently. That means handling similar actions in a similar way with your code, based on decisions made by your team. It also means keeping similar <a href=\"https:\/\/make.wordpress.org\/core\/handbook\/best-practices\/coding-standards\/php\/#naming-conventions\" target=\"_blank\" rel=\"noreferrer noopener\">naming conventions<\/a> for files and functions. For the best reliability and insurance that your code won\u2019t break when WordPress updates, make sure the way you call <a href=\"https:\/\/make.wordpress.org\/core\/handbook\/best-practices\/coding-standards\/php\/\">classes, functions, and hooks<\/a> is in alignment with WordPress core. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Flexibility<\/h3>\n\n\n\n<p><b><span style=\"font-weight: 400\">Last, ensure that your code is flexible enough to be edited in the future. This means using relative URL paths wherever possible, and leaving room to grow in the future. This means if your URL changes, you won\u2019t be stuck having to edit all the code that calls that specific URL. And ensuring you are structuring your code and content in an <a href=\"https:\/\/make.wordpress.org\/core\/handbook\/best-practices\/coding-standards\/accessibility-coding-standards\/\" target=\"_blank\" rel=\"noreferrer noopener\">accessible way<\/a> also paves the way to expand on this accessibility later on. <\/span><\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Structuring Code in WordPress<\/h2>\n\n\n\n<p><span style=\"font-weight: 400\">As a developer, you know that structuring your code can sometimes be half the battle. Learning best practices for structuring can be instrumental in keeping your code readable, searchable, and consistent. In this section we will cover general structure rules for WordPress. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">File and Directory Structure<\/h3>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1232\" height=\"422\" src=\"https:\/\/wpengine.com\/wp-content\/uploads\/2018\/04\/structure_image.png\" alt=\"the structure beneath a building as it is being constructed. WordPress Best Practices for Developers\" class=\"wp-image-37169\" srcset=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/structure_image.png 1232w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/structure_image-300x103.png 300w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/structure_image-768x263.png 768w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/structure_image-1024x351.png 1024w\" sizes=\"auto, (max-width: 1232px) 100vw, 1232px\" \/><\/figure>\n\n\n\n<p><span style=\"font-weight: 400\"><\/span><span style=\"font-weight: 400\">Within WordPress, it\u2019s important to understand the default file and directory hierarchy. Understanding this structure allows you to place your code in the right location. In the root directory of your website, there will be a few configuration files. The <\/span><i><span style=\"font-weight: 400\">index.php<\/span><\/i><span style=\"font-weight: 400\"> file will be the homepage of your website. The <\/span><i><span style=\"font-weight: 400\">wp-config.php<\/span><\/i><span style=\"font-weight: 400\"> file will fill in important configuration settings for WordPress. And the <\/span><i><span style=\"font-weight: 400\">.htaccess<\/span><\/i><span style=\"font-weight: 400\"> file will give your web server configuration rules. Specifically, the .htaccess file must have the <a href=\"https:\/\/wordpress.org\/documentation\/article\/htaccess\/\" target=\"_blank\" rel=\"noreferrer noopener\">default WordPress rules<\/a>. <\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400\">Within the root directory there are also some important directories:<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><i><span style=\"font-weight: 400\">wp-admin<\/span><\/i><span style=\"font-weight: 400\"> includes the WordPress core files needed to power the WordPress Admin Dashboard for your website. These files should not be edited.<\/span><\/li>\n\n\n\n<li><i><span style=\"font-weight: 400\">wp-includes<\/span><\/i><span style=\"font-weight: 400\"> contains most of the WordPress core files pertaining to core functionality that makes your site tick. These files should not be edited either.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\"><em>wp-content<\/em> <\/span>holds all content provided by users that isn&#8217;t saved in the database including plugins, themes, and items that have been uploaded to the media folder. <\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400\">And within a plugin, it\u2019s best practice to follow the recommended <a href=\"https:\/\/developer.wordpress.org\/plugins\/the-basics\/best-practices\/#folder-structure\" target=\"_blank\" rel=\"noreferrer noopener\">plugin directory structure<\/a><\/span> <span style=\"font-weight: 400\">for your files. This will help you and others working on your project to keep similar files together.<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1458\" height=\"792\" src=\"https:\/\/wpengine.com\/wp-content\/uploads\/2018\/04\/plugin_structure_wordpress.png\" alt=\"plugin directory structure. WordPress Best Practices for Developers\" class=\"wp-image-37163\" srcset=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/plugin_structure_wordpress.png 1458w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/plugin_structure_wordpress-300x163.png 300w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/plugin_structure_wordpress-768x417.png 768w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/plugin_structure_wordpress-1024x556.png 1024w\" sizes=\"auto, (max-width: 1458px) 100vw, 1458px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Template Hierarchy<\/h3>\n\n\n\n<p><span style=\"font-weight: 400\">Another important aspect when developing for WordPress is understanding the <a href=\"https:\/\/developer.wordpress.org\/themes\/basics\/template-hierarchy\/\" target=\"_blank\" rel=\"noreferrer noopener\">template hierarchy<\/a>. The theme template hierarchy will help you determine which template WordPress will choose when building a page or post. WordPress searches through its default template hierarchy to determine which template to use for each post. WordPress will search until it finds a file matching the name of the template. If there are multiple files matching the name of the template, it will use the first one in the template hierarchy.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Separation and Spaces<\/h3>\n\n\n\n<p><span style=\"font-weight: 400\">While functionally some spacing decisions in code are not any different than others, they can make a difference in terms of readability. With that in mind, the uniform way to <a href=\"https:\/\/make.wordpress.org\/core\/handbook\/best-practices\/coding-standards\/php\/#space-usage\" target=\"_blank\" rel=\"noreferrer noopener\">space your PHP code<\/a> is outlined in the WordPress PHP Coding Standards. The general rules when it comes to spacing are:<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400\">Spaces after commas.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Spaces after beginning and before closing parentheses unless otherwise specified<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Only include spaces around array items if it\u2019s a $variable.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Remove whitespace at the end of your code<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">No closing PHP tag is preferable<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400\">And there are more spacing rules in the guide linked above! Coding with these uniform standards will ensure your code is up to par and easy to read. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Design Best Practices<\/h3>\n\n\n\n<p><span style=\"font-weight: 400\">WordPress also has coding standards for the design of your website! You can view their <a href=\"https:\/\/codex.wordpress.org\/Theme_Development#Theme_Development_Standards\" target=\"_blank\" rel=\"noreferrer noopener\">theme handbook<\/a>, as well as the <a href=\"https:\/\/make.wordpress.org\/core\/handbook\/best-practices\/coding-standards\/css\/\" target=\"_blank\" rel=\"noreferrer noopener\">CSS coding standards<\/a> for a thorough guide. While WordPress has very few limitations surrounding your website\u2019s appearance, they do have recommendations for the structure of your CSS. Below are the generally accepted rules of CSS code:<\/span><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400\">Use tab to indent rather than spaces<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Two lines between sections of CSS<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Selectors should be listed on their own line, ending in a comma or brace<figure><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-37162\" src=\"https:\/\/wpengine.com\/wp-content\/uploads\/2018\/04\/css_classes_wordpress.png\" alt=\"\" width=\"627\" height=\"247\" srcset=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/css_classes_wordpress.png 1148w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/css_classes_wordpress-300x118.png 300w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/css_classes_wordpress-768x302.png 768w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/css_classes_wordpress-1024x403.png 1024w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\" \/><\/figure><\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Name selectors using lowercase words separated by a hyphen<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Use hex codes for colors of properties<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Properties should be followed by a colon and a space<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Comment liberally for context<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400\">You can find many more guidelines for style and CSS in general in the guide linked above! When you code according to WordPress standards, it helps your team work together and facilitates understanding. And when you add context clues with many comments, it means the intention and purpose of your code will last far longer than your memory of it will.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing Code in WordPress<\/h2>\n\n\n\n<p><span style=\"font-weight: 400\">It\u2019s not often that you get the development of a new feature, plugin, or child theme exactly right the first time. One thing that can facilitate the trial and error of development is to employ Test Driven Development (TDD) methods. The idea behind Test Driven Development is to write a test before you\u2019ve written any code. Then, write just enough code to make that test pass successfully. As you add to the code to add more functionality, add more tests first. In doing so you will save yourself the time of building larger tests with potential holes in the future.<\/span><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1942\" height=\"542\" src=\"https:\/\/wpengine.com\/wp-content\/uploads\/2018\/04\/codeception_logo.png\" alt=\"Codeception for WordPress. WordPress Best Practices for Developers\" class=\"wp-image-37168\" srcset=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/codeception_logo.png 1942w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/codeception_logo-300x84.png 300w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/codeception_logo-768x214.png 768w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/codeception_logo-1024x286.png 1024w, https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/codeception_logo-1500x419.png 1500w\" sizes=\"auto, (max-width: 1942px) 100vw, 1942px\" \/><\/figure>\n\n\n\n<p><span style=\"font-weight: 400\">A very handy tool to assist with WordPress development and testing is <a href=\"https:\/\/codeception.com\/quickstart\" target=\"_blank\" rel=\"noreferrer noopener\">Codeception<\/a>. Codeception is unique in that it provides Functional WordPress Tests, Integration Testing, and User Acceptance Testing. Using these tools you can test your code against WordPress standards, ensuring a positive experience for your end users. <\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400\">In an ideal development workflow, your team can use Test Driven Development methods within an Agile development system. This means allowing your team members to \u201ccheck out\u201d code from your central library, make changes, commit it back into the library, and regularly deploy those changes to your website. You can learn more about <a href=\"https:\/\/wpengine.com\/resources\/ultimate-guide-agile-development-wp-engine\/\" target=\"_blank\" rel=\"noreferrer noopener\">Agile Development for WordPress<\/a> in our Whitepaper. <\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Get Support for More Common WordPress Questions with WP Engine<\/h2>\n\n\n\n<p><span style=\"font-weight: 400\">When you host your websites on the WP Engine, your plan comes with 24\/7\/365 support from our team of <a href=\"https:\/\/wpengine.com\/wordpress-hosting\/\" target=\"_blank\" rel=\"noreferrer noopener\">WordPress hosting<\/a> experts. And your plan will also include staging and development environments in which to test your code! A site with multiple environments can unlock powerful developer workflows for your team. Curious to learn more?<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article explains the importance of following WordPress Best Practices as a developer. Learn how to write and structure your code properly, test it against WordPress Core standards, and best practices for site creation and management in our developer starter guide. Most importantly, gain tangible insights for how to implement these strategies and practices on<span class=\"tile__ellipses\">&hellip;<\/span><span class=\"tile__ellipses--animated\"><\/span><\/p>\n","protected":false},"author":1,"featured_media":37171,"template":"","resource-topic":[901],"resource-role":[895,896,897,1296],"resource-type":[916],"class_list":["post-37161","resource","type-resource","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>WordPress Best Practices for Developers<\/title>\n<meta name=\"description\" content=\"WP Engine offers WordPress advice for deployment and developers to help them prevent common WordPress mistakes.\" \/>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress Best Practices for Developers\" \/>\n<meta property=\"og:description\" content=\"WP Engine offers WordPress advice for deployment and developers to help them prevent common WordPress mistakes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Engine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/wpengine\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-09T17:22:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/developer_best_practices_wordpress_banner.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"WordPress Best Practices for Developers\" \/>\n<meta name=\"twitter:description\" content=\"WP Engine offers WordPress advice for deployment and developers to help them prevent common WordPress mistakes.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/developer_best_practices_wordpress_banner.png\" \/>\n<meta name=\"twitter:site\" content=\"@wpengine\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/\",\"url\":\"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/\",\"name\":\"WordPress Best Practices for Developers\",\"isPartOf\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\"},\"datePublished\":\"2020-09-29T12:39:00+00:00\",\"dateModified\":\"2024-01-09T17:22:36+00:00\",\"description\":\"WP Engine offers WordPress advice for deployment and developers to help them prevent common WordPress mistakes.\",\"breadcrumb\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wpengine.com\/case-studies\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Resources\",\"item\":\"https:\/\/wpengine.com\/case-studies\/resources\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"WordPress Best Practices for Developers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\",\"url\":\"https:\/\/wpengine.com\/case-studies\/\",\"name\":\"WP Engine\",\"description\":\"Managed Hosting for WordPress\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/f5301455463371a10d1fc290e9ad0085\",\"name\":\"WP Engine\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g\",\"caption\":\"WP Engine\"},\"sameAs\":[\"https:\/\/wpengine.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress Best Practices for Developers","description":"WP Engine offers WordPress advice for deployment and developers to help them prevent common WordPress mistakes.","robots":{"index":"noindex","follow":"follow"},"og_locale":"en_US","og_type":"article","og_title":"WordPress Best Practices for Developers","og_description":"WP Engine offers WordPress advice for deployment and developers to help them prevent common WordPress mistakes.","og_url":"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/","og_site_name":"WP Engine","article_publisher":"https:\/\/www.facebook.com\/wpengine","article_modified_time":"2024-01-09T17:22:36+00:00","og_image":[{"width":1100,"height":400,"url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/developer_best_practices_wordpress_banner.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_title":"WordPress Best Practices for Developers","twitter_description":"WP Engine offers WordPress advice for deployment and developers to help them prevent common WordPress mistakes.","twitter_image":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/developer_best_practices_wordpress_banner.png","twitter_site":"@wpengine","twitter_misc":{"Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/","url":"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/","name":"WordPress Best Practices for Developers","isPartOf":{"@id":"https:\/\/wpengine.com\/case-studies\/#website"},"datePublished":"2020-09-29T12:39:00+00:00","dateModified":"2024-01-09T17:22:36+00:00","description":"WP Engine offers WordPress advice for deployment and developers to help them prevent common WordPress mistakes.","breadcrumb":{"@id":"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wpengine.com\/case-studies\/resources\/developer-best-practices\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wpengine.com\/case-studies\/"},{"@type":"ListItem","position":2,"name":"Resources","item":"https:\/\/wpengine.com\/case-studies\/resources\/"},{"@type":"ListItem","position":3,"name":"WordPress Best Practices for Developers"}]},{"@type":"WebSite","@id":"https:\/\/wpengine.com\/case-studies\/#website","url":"https:\/\/wpengine.com\/case-studies\/","name":"WP Engine","description":"Managed Hosting for WordPress","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/f5301455463371a10d1fc290e9ad0085","name":"WP Engine","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g","caption":"WP Engine"},"sameAs":["https:\/\/wpengine.com"]}]}},"acf":[],"grid_image_url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2018\/04\/developer_best_practices_wordpress.png","media-type":{"term_id":916,"name":"Article","slug":"article"},"role":"<strong>Roles:<\/strong> Agency, Developer, Freelancer, Publisher","topic":"<strong>Topics:<\/strong> WordPress","_links":{"self":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource\/37161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource"}],"about":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/types\/resource"}],"author":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/users\/1"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media\/37171"}],"wp:attachment":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media?parent=37161"}],"wp:term":[{"taxonomy":"resource-topic","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-topic?post=37161"},{"taxonomy":"resource-role","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-role?post=37161"},{"taxonomy":"resource-type","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-type?post=37161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}