WordPress Development


Table of Contents

1 WordPress Links to documentation

1.1 Proxy to HTTPS

add to wp-config.php

if($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
  $_SERVER['HTTPS'] = 'on';
  $_SERVER['SERVER_PORT'] = 443;

1.2 Optimize WordPress Revisions

1.2.1 Delete WordPress Revisions With WP-CLI

$ wp post delete --force $(wp post list --post_type='revision' --format=ids)

1.2.2 Limit Number of WordPress Revisions

Open your wp-config.php file. The code below needs to be inserted above the ‘ABSPATH’ otherwise it won’t work. Again, you can change the number to however many of revisions you want to keep stored in your database per page or post.

define('WP_POST_REVISIONS', 3);

1.3 How to Speed up Your WordPress Site (Ultimate 2019 Guide)

1.4 WordPress Cache


sudo apt-cache search opcache
php7.2-opcache - Zend OpCache module for PHP


The Definitive PHP 5.6, 7.0, 7.1, 7.2 & 7.3 Benchmarks (2019) https://kinsta.com/blog/php-benchmarks/

1.5 WP Super Cache Plugin: Settings & Configuration Guide to use in 2019

1.7 How to Eliminate Render-Blocking JavaScript and CSS

1.8 How to Use Redis as a Persistent Object Cache for WordPress

1.9 How to Fix the Leverage Browser Caching Warning in WordPress

2 wp-cli useful examples

2.1 Installing WordPress

I use WP-CLI a lot to set up test environments, the first step of which is a vanilla installation. Here is a list of commands I run:

wp core download
wp core config --dbname=mydbname --dbuser=mydbuser --dbpass=mydbpass --dbhost=localhost --dbprefix=whebfubwef_ --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
wp db create
wp core install --url=http://siteurl.com --title=SiteTitle --admin_user=username --admin_password=mypassword --admin_email=my@email.com

2.2 Reinstall WordPress Core

You can also reinstall WordPress core using WP-CLI. The following command would download WordPress core without the default themes and plugins.

wp core download --skip-content --force

2.3 Change WordPress URL

There are many reasons why you might need or want to change your WordPress URL. Perhaps you are changing domains, moving to a subdomain, updating from www to non-www, moving files around, or even migrating from HTTP to HTTPS. Whatever the case may be, you can use easily use the wp option update command for this. Here is an example below:

wp option update home 'http://example.com'
wp option update siteurl 'http://example.com'

2.4 List of Current Plugins with Details

wp plugin list

2.5 Installing Multiple Plugins

Note that the plugin names come from their name in the repository. The easiest way to figure this out is to visit their page and look at the URL or to use wp plugin search searchterm which will give you a list in the terminal.

wp plugin install advanced-custom-fields jetpack ninja-forms --activate

You can also install older versions of WordPress plugins if needed with the –version attribute.

wp plugin install wordpress-seo --version=4.8 --activate

Even cooler, you can install plugins from remote files, not just the repository which is handy if you’re developing a plugin, or using a premium plugin. The following command installs two plugins from the repository and one from an Amazon S3 server.

wp plugin install advanced-custom-fields jetpack https://d1qas1txbec8n.cloudfront.net/wp-content/uploads/2015/06/23073607/myplugin.zip --activate

2.6 Deactivate Multiple Plugins

To deactivate a single plugin you can run the following command.

wp plugin deactivate wordpress-seo

To deactivate all your plugins at once run the following command.

wp plugin deactivate --all

2.7 Update Plugins

You can also manually update WordPress plugins. Example below:

wp plugin update wordpress-seo

2.8 Database Search And Replace

One of the main reasons it is difficult to migrate a site by just copy-pasting a database is that the database contains serialized arrays. If you need to replace all instances of http://testsite.com with http://livewebsite.com your serialized arrays will not make sense because the string count won’t match up.

The search-replace command unserializes arrays first, then performs the search and replace, then re-serializes the arrays. You can get this done with a simple command. Additional parameters allow you to do a lot more, including preview what will be replaced by using –dry-run.

wp search-replace oldstring newstring

2.9 Import And Export

There are two ways to export content with WP-CLI. You can create an XML file, just like the WordPress export tool does, or you can export/import the raw database. I find the later a lot more useful in my daily routine, it comes in handy when syncing sites.

wp db export is all you need to do to create a SQL file and wp db import file.sql is all you need to import it. Works like a charm, just be careful not to overwrite anything you need, importing will basically dump the existing database and use the supplied SQL file instead.

wp db export
wp db import file.sql

2.10 DB Queries


echo "desc wp_comments" | wp --allow-root db query

# Execute a query stored in a file
$ wp db query < debug.sql

# Check all tables in the database
$ wp db query "CHECK TABLE $(wp db tables | paste -s -d, -);"

# Print last comment
echo "select * from wp_comments order by comment_ID desc LIMIT 1 \G" | wp --allow-root db query

3 Your WordPress Theme Matters

3.1 GeneratePress

GeneratePress is a fast, lightweight (less than 1MB zipped), mobile responsive WordPress theme built with speed, SEO and usability in mind. Built by Tom Usborne, a developer from Canada. It is actively updated and well supported. Even a few Kinsta team members use GeneratePress for their projects.



3.2 OceanWP

The OceanWP theme is lightweight and highly extendable. It enables you to create almost any type of website, such as a blog, portfolio, business website or WooCommerce storefront with a beautiful & professional design. Built by Nicolas Lecocq, it is also actively updated and well supported.



3.3 Astra

Astra is a fast, fully customizable & beautiful theme suitable for blogs, personal portfolios, business websites, and WooCommerce storefronts. It is very lightweight (less than 50 KB on frontend) and offers unparalleled speed. Built by the team at Brainstorm Force, it is actively updated and well supported. You might recognize them as the creators of the popular All In One Schema Rich Snippets plugin which has been around for many years.

3.4 Warning About Page Builders

As you probably noticed, OceanWP and Astra both required page builders to use their site library themes. Here are a few things to keep in mind when using a page builder plugin:

Some page builders might increase load time on your site. This is because they have to load additional CSS and JS to make things work for you without code. That is how the magic happens! We always recommend speed testing your WordPress site before and after installing a page builder. You’re making committing and locking yourself into that page builder for design. Make sure you pick one that is regularly updated and has everything you need for the long haul.


4.1 Trellis, Bedrock, Sage are the best thing to ever happen to any developer working with WordPress. ??

4.2 The Twelve-factor methodology

4.3 Grav is a modern open source flat-file CMS

4.4 Francesco Carlucci blog

Author: Sebastian Emilio Narvaez

Created: 2020-01-28 Tue 16:31

Emacs 25.2.2 (Org mode 8.2.10)