WordPress Best Practices
A list of suggestions for developing WordPress sites on Pantheon.
This article provides suggestions, tips, and best practices for developing and managing WordPress sites on the Pantheon platform.
Do not modify core WordPress files as it can cause unintended consequences, and can prevent you from updating your site regularly. If you need to modify any WP functionality, do it as a custom plugin, which adheres to the WP.org Plugin best practices.
Use Redis. Redis is an open-source, networked, in-memory, key-value data store that can be used as a drop-in caching backend for your WordPress site. Pantheon makes it super simple and you'll be able to catch a lot of database queries in WordPress.
Use wp-cfm. It lets you store settings from the
wp_optionstable in Git and pull it into the database. A lot of WordPress stuff is option-heavy and you can spend a lot of time trying to figure out what you missed between environments. This is true for all WordPress sites, but especially helpful on Pantheon where you have at least three environments you will need to reconfigure every time.
When developing custom plugins or themes, it is best to abide by the WordPress Coding Standards for efficiency and ease of collaboration.
Add Composer and pull your WordPress plugins from wpackagist.org. WordPress Packagist mirrors the WordPress.org plugin repository and adds a composer.json file so things play nice. It makes future debugging much simpler should you need to switch between multiple plugin or WordPress versions to see what caused something to break. While committing Composer dependencies is generally not recommended, you will have to commit the dependencies that Composer downloads on Pantheon since running
composer installon the environments is not supported (just as Git submodules are not supported).
If you have a custom plugin that retrieves a specific post (or posts), instead of using
wp_query()to retrieve it, use the
get_post()function. While wp_query has its uses, the get_post function is built specifically to retrieve a WordPress Post object, and does so very efficiently.
Don't use plugins that create files vital to your site logic that you aren't willing to track in Git. Sometimes they're dumped in uploads, sometimes not, and you'll likely have difficulty trying to figure it out later. You'd be surprised how many uploads-type plugins rely on
.htaccessfiles — avoid those as well.
In your theme, use a simple PHP
include()instead of WordPress's get_template_part(). The overhead is heavy if your use case is simply adding in another sub-template file. For example:
<?php get_template_part('content', 'sidebar'); ?> <?php include('content-sidebar.php'); ?>
Run Launch Check to review errors and get recommendations on your site's configurations.
Automate testing with Behat. Adding automated testing into your development workflow will help you deliver higher quality WordPress sites.