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.

  • 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.

  • Verify Global CDN caching is working on your site.

  • Use wp-cfm. It lets you store settings from the wp_options table 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.

  • Automate testing with Behat. Adding automated testing into your development workflow will help you deliver higher quality WordPress sites.

  • We recommend using HTTPS. For more information, see HTTPS on Pantheon's Global CDN

  • Run Launch Check to review errors and get recommendations on your site's configurations.

  • We recommend using an IDE, or a text editor designed for development like Atom, Sublime Text, or Brackets.

  • 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 .htaccess files — avoid those as well.

  • Use Grunt or Gulp to aggregate JS/CSS on your local development environment rather than relying on the server to do it for you. This helps speed up your workflow by minimizing redundant tasks.

  • Add Composer and pull your WordPress plugins from wpackagist.org. WordPress Packagist mirrors the WordPress.org plugin repo 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 install on the environments is not supported (just as Git submodules are not supported).

  • In your theme, use a simple PHP include() instead of WordPress' 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'); ?>
    
  • 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.