Adding Estimated Read Time to a WordPress Post

Ever since Medium popularized the concept of the read times on articles, I’ve been seeing it as a design element in more WordPress projects.

Getting a great estimate for average read time is complicated, but if you just need a blunt tool for calculating it, you can use:

amount of words in the post / average reading speed

According to Medium, people read about 275 words per minute. Medium also adds 12 seconds for each inline image, but I didn’t get that fancy.

Here’s the snippet:

https://gist.github.com/devinsays/cd6b089dd2f138bcf668d5f938e38dbf#file-estimate-read-time-php

To output the read time in your post, use something like this:

https://gist.github.com/devinsays/cd6b089dd2f138bcf668d5f938e38dbf#file-output-php

If you prefer to use a plugin, there’s a few around. This snippet is mostly borrowed code from Reading Time WP, which is also on GitHub.

Prevent WordPress Emails in Stage or Local Environments

When you’re developing a WordPress site locally or testing in staging, you’ll generally want to prevent the site from sending out emails to customers or users.

I’ve noticed that a number of other WordPress developers are fans of MailHog (great write up by Jonathan Christopher), but in many cases it’s easier if you don’t have to install anything additional on the server.

I use two plugins to block and then log emails:

“Disable Emails” prevents the emails from sending from WordPress, and “Email Log” is able to capture their contents in case you need to view them.

Since I sync my production environment to staging and local quite frequently, I have a script in my theme that activates these plugins when it detects the new environment.

Automatic Accounts on WooCommerce Checkout

There are a lot of good reasons to require a customer account on checkout:

  • It’s easier for customers to manage their orders and get support.
  • It’s for customer to purchase again (all their details are saved).
  • It’s easier for store manager to track life time value of customers.

However, the checkout process for first time customers should still be as seamless as possible. This is why I like to create accounts automatically if the email hasn’t been used before. WooCommerce has this functionality built-in. Continue reading