WordPress code I always use on new installs

I set up a lot of WordPress sites and I keep text files of the bits of code I add to the .htaccess file and config file on all new installs.

To keep WordPress going smoothly, there are a few bits of code I add to files when I install WordPress on a new domain.

Increase Memory Limit

To increase the allowed memory size from the standard 40M to 256M I use the following code in wp-config.php (usually in the /public_html/ folder:

define('WP_MEMORY_LIMIT', '256M');

Replace the 256M with 96/128/256 but I find that 128M will suffice for most sites.

Disable WP-Cron

Until recently, I left the wp-cron to handle daily tasks with WordPress. I was advised by my hosts to switch to cPanel to handle cron jobs, this is more efficient and improves performance and reduces server load significantly.

In the same file as before, wp-config.php enter the code below. I usually put it after the database collate information [define(‘DB_COLLATE’, ”);], don’t forget to save:

define('DISABLE_WP_CRON', 'true');

This will disable the wp-cron from running – you must enable the file to be run by your server. Login to your host backend, usually cPanel, click on Cron Jobs (Advanced section) and enter the command:

/usr/local/bin/php ~/public_html/wp-cron.php >/dev/null 2>&1

The first part /usr upto php depends on your host. They will usually have a post in their knowledgebase or you can message support for advice. The second part is the actual location of the wp-cron.php file. The >/dev/null 2>&1 just disables e-mail notifications, you will receive loads if left active.

If like me, you install WordPress into the root directory then [username]/public_html/wp-cron.php should be fine. My host setup may differ to yours and I don’t need to specify the username.

After you enter that, you can choose the times to run under common settings, my host suggested twice every hour, some suggest once an hour or once every 6 hours if you don’t have much traffic or make regular changes.

For The Newsletter plugin I changed the frequency to once every 5 minutes as that is the recommended time for that plugin.

SSL Redirect

As all of my WordPress sites have SSL installed by default and I install to the base url without the www I add the following code to my .htaccess file to divert everything to the base url:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{HTTPS} off
 RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 </IfModule>

I made another post on this here where I had issues with icons

Leave a comment

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest DEALS, OFFERS and News before anyone else.

You are almost done - please check your inbox for confirmation!

Pin It on Pinterest

Share This