WordPress table plugin

Our sortable table WordPress plugin - Posts Table Pro - lets you display various types of content from your WordPress website in a searchable and sortable jQuery table.

Based on the jQuery DataTables plugin, your visitors can view your posts, pages, or other content from your website in a fully sortable table.

You can set up the WordPress table to sort by any column by default, and you can change the default sort order. Your visitors can click the column headers to sort the table as they wish. They can also search for a keyword or filter the table by category, tag, custom taxonomy, etc.

In this video tutorial, I explain how to install and configure Posts Table Pro, using the example of a staff directory to help you create a sortable table. If you prefer written instructions, please see below for a step-by-step written tutorial.

The best WordPress sortable table plugin

Posts Table Pro is the premium version of our free sortable table plugin for WordPress - Posts Table with Search & Sort.

The free plugin lets you display blog posts from your WordPress website in a searchable, sortable table. The Posts Table Pro plugin builds on this by adding support for custom post types, custom fields, and custom taxonomies. It has various other options to create more sophisticated sortable tables.

WordPress sortable table plugin

Posts Table Pro is perfect for many different use cases including:

As you can see, the Pro plugin lets you create sortable tables in WordPress for many use cases that aren't available with the free plugin.

How to set up the Posts Table Pro sortable table plugin

1. Install the plugin

  1. First of all, you purchase the plugin on our website and download the plugin.
  2. Then you go into your WordPress admin and go to Plugins → Add New.
  3. Then you click Upload → Choose File and select the file from the link in your order confirmation email. This will save a zip file to your computer.
  4. Once uploaded, click Activate.
  5. After activation, the Posts Table Pro setup wizard will automatically open and guide you through entering your license key.

Now we'll use the plugin to create a WordPress Staff Directory. It will add a simple staff list to your website with links to the staff profiles. The list will appear in a searchable, sortable table. You can use the plugin to display various types of content, so this is just an example.

2. Add the information to display in the WordPress table

Post Table Pro's role is to create a sortable table of content already on your website. It does not create custom post types or taxonomies or anything, it just displays them. So you would add those previously using whatever method you're using to set up your website and data. You then get Posts Table Pro to allow you to display that data within a table.

If you want a separate 'Staff' section in the WordPress admin to store your staff data, I recommend the Easy Post Types and Fields plugin to create a custom post type and any extra fields of information. I used this to create a Staff custom post type and add various data relating to the staff profiles. Once you've decided how to store your staff data, go ahead and add all your staff members to the website.

3. Create your sortable table in WordPress

https://barn2.com/wordpress-content-table/
  1. Upon installing the plugin, an automatic setup wizard will initiate, guiding you through the process of creating your first table. The setup wizard takes you through a step-by-step process, making it easy for you to create a sortable table that suits your needs.
  2. To begin creating your sortable table, you'll need to provide a name for it and select the post type that you want to display. After that, you can choose the posts or pages that you wish to include in the table.
  3. The plugin allows you to choose from a range of options, including posts, pages, and custom post types. Suppose you're building a database and want to include documents. In that case, you can select the custom post type option and proceed accordingly.
  4. The plugin offers a wide range of customization options, allowing you to determine which columns to display and in what order. To add a new column, choose the column type from the dropdown menu and click "Add". You can also reorder columns by dragging and dropping the sort icon or column heading.
  5. You can also add filters to your table. Filters appear as dropdowns above the table, and you can add as many as you like.
  6. To customize the sorting options for your table, select the default sorting option and the sort direction that you prefer. This gives you complete control over the order in which your table is displayed.
  7. If you're dealing with a large amount of data, you can enable lazy loading to improve the table's performance. This ensures that even when your table contains hundreds or thousands of items, it loads quickly and smoothly.
  8. Next, you can choose how to sort your database, setting the default sorting option and the sort direction that you prefer. With all these options, you can create a table that is functional, easy to use, and visually appealing to your users.
  9. Finally, once you have completed creating your sortable table using the Post Table Pro plugin, the setup wizard will confirm that you have finished and provide you with instructions for displaying the table on your WordPress site. You have two options for displaying the table: using the 'Post Table' block in the Gutenberg editor, or copying the shortcode from the table builder and pasting it anywhere on your site. This gives you the flexibility to place the table on any page regardless of its content.

Create sortable tables more easily

The Posts Table Pro plugin is a versatile and user-friendly tool for creating sortable tables on WordPress websites. With its easy-to-use setup wizard and customizable features, you can create sortable tables that suit your specific needs, whether it's for displaying blog posts, product listings, or other types of content.

The plugin's ability to add filters and customize sorting options makes it easy for users to navigate and find the information they need quickly. Overall, the Posts Table Pro sortable table plugin is a must-have for website owners who want to enhance their user experience and improve the organization of their content.

We have created a video tutorial explaining how to use our WordPress password protect plugin to protect a WooCommerce category. The plugin lets you add password protections to a category and its products, or restrict it to specific logged in users or roles. Watch this alongside reading the knowledge base.

WooCommerce Password Protect pluginThe tutorial tells you how to create a WooCommerce password protected category and private category in WooCommerce. It also explains the logic behind the plugin and how once you have protected a category, it will automatically protect all its products and any sub-categories too.

Here's a written tutorial for those of you who don't like videos:

Written transcript of WooCommerce Password Protect Category video

Before we learn how to password protect a WooCommerce category, you need to get the plugin on our website. Download the file and install it in the usual way for a WordPress plugin (Plugins → Add New → Upload), and also add the license key from your confirmation email.

Once you've got that all set up, you should have WooCommerce and WooCommerce Protected Categories installed on your website. You need both these plugins in order for WooCommerce Password Protect Category to work.

How to password protect a category in WooCommerce

Next go to Products → Categories in the WordPress admin. This is the usual page where you can create a WooCommerce category. If you've got an existing website then you probably have categories on the right already - that's fine. The process for creating a WooCommerce password protected category is exactly the same whether it's a new category or an existing one.

Let's great a new category. In the 'Add New Category' section on the left, add the following:

  • Category name - e.g. 'Clothes'
  • Slug - this is the last part of the category URL, e.g. 'clothes'

If you scroll down, you'll see that there's a new section at the bottom called 'Visibility'. This is what the WooCommerce Password Protect Categories plugin has added and it's not there by default in WooCommerce.

To password protect a WooCommerce category, you simply tick the 'Protected' option and enter a password, which can be anything you like. You can also set the category to only be visible to certain logged in users or user roles. Then click 'Add New Product Category'.

Click the plus (+) icon to add multiple passwords for a category. This lets you give different passwords to different customers.

This will add your new category in the list of categories on the right. In the 'Visibility' column, you can see that it is labelled 'Password protected'.

You can also restrict categories to specific users or entire roles. That way, they can automatically see the hidden content as soon as they log into their account. They don't need to enter a separate password.

Password protect sub-categories

You can also add sub-categories. If you have a sub-category, it will automatically share the same password. You don't need to password protect it - it just happens automatically.

Let's do this now and create a new category called 'Shoes'. I'm going to select the Parent as 'Clothes', and mark it as Public as I don't need to password protect it. Because this is a child category of a password protected category, it will be password protected even though it doesn't have its own password.

The great thing about that is that if you give your customers a password for the parent category, they can use it to access any of the products in that category, the child category page and any of the products in the child category. Customers only need to enter the password once and that whole area of the website will be unlocked for them.

That's much better than password protecting each individual product, which would be a nightmare for the customer because they'd have to enter the password for every single product they want to view. Not ideal!

If you want to create more complex structures for a password protected category, you can add other protected categories with their own password. For example, you might have a 'Furniture' WooCommerce category which is separate from the 'Clothes' category. You would add a different password to protect the Furniture category. That will work alongside the Clothes category and each will have a completely different password to protect it. If you give the customers who buy your clothes the password for the Clothes category, they will be able to access the Shoes category because it's a child category of Clothes. However they cannot access the Furniture category which is protected separately.

This is a good way to lock down lots of different types of WooCommerce store. For example you might use a password to protect a Trade section of your WooCommerce website and give the password to your trade distributors. You could give them each their own category and their own password. Or whatever the use case for you.

WooCommerce Password Protected Category settings

There are various settings for the WooCommerce Password Protect plugin in WooCommerce → Settings → Products → Protected Categories. These let you control how your protected WooCommerce categories appear on the main Shop page and in navigation menus and widgets. You can also customize the text on the password entry page.

Wrapping up our WooCommerce password protect tutorial

So that's how you set up the plugin and password protect a WooCommerce category. Give the password to your customers and they can buy from the protected categories.

For more information, check out our tutorials on how to hide a whole WooCommerce store and make it private, and how to use it as a WooCommerce wholesale plugin. If you want to protect an entire store, it's also worth looking at our dedicated private shop WooCommerce plugin.

Or sign up as an affiliate and earn 30% commission for recommending the plugin!

In response to popular demand, we have launched a new WordPress plugin called WooCommerce Password Protected Categories. It's the only plugin which lets you password protect categories in WooCommerce. It's even possible to create a WooCommerce wholesale site or hide a whole WooCommerce store!

Note: Since launching this plugin, we have added extra functionality and renamed it 'WooCommerce Protected Categories'. You can still password protect product categories, but you can also restrict categories to specific roles or even individual users. This makes it the most complete WooCommerce category protection plugin on the market. 

Why password protect WooCommerce categories?

WooCommerce Private Products pluginThere are several reasons why you might want to password protect a category or create WooCommerce private products. Here are some popular examples:

Most WooCommerce websites are entirely available to the public. However with nearly 2 million websites using WooCommerce in 2017, there are also lots of stores that need protected, private or hidden areas.

Related tutorial: How to create WooCommerce private products.

What does WooCommerce Password Protected Categories do?

WooCommerce Private Products WordPress pluginWooCommerce Protected Categories adds a password protection option to the WooCommerce Categories page (WooCommerce → Categories in the WordPress admin). It works in the same way as the password protection for pages and posts. You choose a password, and visitors must enter this password in order to access the category page.

Each WooCommerce product category can have one password. Alternatively, you can create multiple passwords for each category. This is useful if you want to create unique passwords for each category, for example.

The great thing about this plugin is that the password automatically protects all the products within the category you have protected. It also protects any sub-categories. This lets you divided up the protected area of your e-commerce store, creating a more complex navigation structure with as many products and sub-categories as you like - all protected by a single password.

The plugin also lets you mark categories as Private, so that only logged in Administrators and Editors can view them. Or if you prefer, you can restrict categories to specific logged in user accounts or user roles. These are all great ways to create WooCommerce private products within a single category.

What did people do before this plugin was released?

Previously, people wanting to create a hidden area for private products within a WooCommerce online shop would use one of the following methods.

Password protect or private WooCommerce products

You can password protect individual WooCommerce products in the same way as you can protect a standard WordPress post or page. You can also create individual WooCommerce private products. Do this via the 'Visibility' option in the 'Publish' section at the top right of the Add/Edit Product screen.

A password protected product will still appear on your main Shop page and category pages. If someone clicks on it then they will be prompted to enter a password before they can view the product.

With this option, you have to individually password protect every product that you need to hide. Or mark the product as private.

With password protected products, your customers will have to enter a password for every single product. Not very user-friendly.

With WooCommerce private products, they appear to logged in users with the correct privileges but it's a bit disjointed.

The WooCommerce Protected Categories plugin offers a more sophisticated solution because it includes a setting allowing you to hide products within private or password protected categories from the main Shop page. You can also hide private or password protected categories from your main list of categories. This means that people will only be able to find your protected products or categories if they have the link. (Or if they're logged in, with WooCommerce product categories.) This lets you have a private area of your WooCommerce shop without cluttering up your public shop pages.

Once a visitor has entered the password for a category, they will be able to view all the products within that category - and also within any sub-categories - without entering any further passwords. This is much more user-friendly than protecting each individual product.

Display products on a private or password protected page

WooCommerce Private Products WP pluginWooCommerce has lots of built-in shortcodes which can be used to display products within a page. Some themes also have options for displaying WooCommerce private products or categories on a standard page.

You can use this to create a standard page in WordPress and password protect it in the usual way or mark it as private. You can then insert the required products onto the page.

The problem with this option is that it's not very secure as there are various other ways that people can find your products. The 'hidden' products will still be visible on your main WooCommerce Shop page which lists all your products - and people can guess the address of this page even if you haven't added any links to it.

If your hidden products are in the same category as publicly available products then visitors will be able to see the hidden products on the category page. There are probably other loopholes, too.

Restrict content using a membership plugin

For a more fully featured solution, you can create a complete membership site using a WooCommerce membership plugin such as WooCommerce Memberships or Groups (with the Groups for WooCommerce add-on). With a membership plugin, each of your users will have their own login details - as opposed to a shared password for each category.

This is a good option if your users will have access to other protected content, for example a wider members area. It's also good if any of your WooCommerce categories are particularly sensitive and a shared password isn't secure enough. However it can be overkill if your requirements are more straightforward than this. WooCommerce-compatible membership plugins are also more expensive. And it's a pain to have to spend your time helping members who are having problems logging in (yes I know WordPress has a 'Lost Password' feature, but owners of membership sites still receive constant enquiries about this.)

If you really want each user to have a separate login then you can create private categories instead of a whole membership plugin. This will automatically unlock your private categories to logged in users depending on their role. It's much easier than a full membership solution.

If you need to create a private area of your shop then the WooCommerce Protected Categories plugin is a great option. It's quick and easy to set up, and automatically protects all the products within your private or password protected categories. Simple!

Create a WooCommerce age restricted store

Password Protected Categories is ideal as a WooCommerce age verification plugin. You can use a password protected category to require customers to verify their age before they can view the age restricted products within.

Is it easy to use?

Absolutely, you can literally create WooCommerce private products within a minute or two. You can read the full plugin documentation here. We've also provided a detailed video tutorial on using the password protection plugin and marking products as private.

Where can I get the WooCommerce private products plugin?

So you'd like to password protect your WooCommerce categories or make them private! You can buy the plugin from here. It's much cheaper than setting up a full membership solution and we hope it is useful for making WooCommerce private and protected.

Or if you'd rather protect your entire shop, check out our WooCommerce Private Store plugin instead.

We've also created an opportunity to earn money from recommending the plugin. Sign up to our WordPress affiliate scheme and get 30% commission for WordPress plugin sales on our site.

How to collect ip addresses from WordPress comments

A client recently asked how to find out the IP address of everyone who leaves a comment or submits a contact form on their WordPress website.

There's a simple answer to the question, but it's not one that most people know. The solution doesn't even involve installing any extra plugins (apart from the plugin you are already using for the contact form). I hope this post helps other people who have the same question about their website.

WordPress comments and IP addresses

If you want to find out the IP address of everyone who comments on your WordPress posts, don't bother looking for a plugin to do this. It's already built into WordPress.

Simply go to the 'Comments' section in the WordPress admin. The IP address appears in the left hand column (titled 'Author') immediately underneath the commenter's name and email address.

You've probably seen it dozens of time but never noticed.

Contact Form 7 and IP addresses

Contact Form 7 is the most popular free WordPress contact form plugin. It's actively used on over 1 million websites worldwide.

I remember Contact Form 7 being quite basic a few years ago. However since then, it has been actively developed. Many new features have been added, making it a highly sophisticated contact form plugin.

One of Contact Form 7's lesser known features is the Remote IP tag. Add the following shortcode anywhere within the Message Body section in the Mail tab in your contact form settings:

[_remote_ip]

Adding this shortcode will automatically insert the user's IP address into the email notification that the administrator receives whenever a new form is submitted on the website.

Warning: You do NOT need to add the [_remote_ip] shortcode to the actual form. You only need to add it to the 'Mail' tab so that the IP address is added to the email that you receive when someone submits the form.

How to track IP addresses using Gravity Forms

Gravity Forms is the world leading premium WordPress contact form plugin. As you would expect from a paid-for plugin used on over 1 million websites, it already has this feature built in.

To insert the user's IP address into the email notification to the administrator, add the following merge tag anywhere within the body for the email:

{ip}

You can read more on Gravity Forms' Merge Tags page.

AdapPymntRolesApp_BOne of our WooCommerce clients recently asked us to set up her WordPress online shop to automatically pay a profit share to her business partner.

Most WordPress e-commerce websites accept payments to a single source only. Typically, a WooCommerce store will integrate with a single PayPal account, to which all payments received via the website are sent. This client wanted a percentage commission or profit share to be automatically paid to a second PayPal account for specific products only.

WordPress plugins for WooCommerce profit share or commission

We initially thought that this would involve some bespoke WordPress development work involving WooCommerce and the PayPal API. However we found several WordPress plugins that met the requirements exactly. I guess that's not surprising given that 2,500+ WooCommerce add-ons are available in 2017.

These plugins work using a feature called PayPal Adaptive Payments. It lets you split a PayPal payment (e.g. from a WooCommerce product order) to multiple recipients.

There are 3 main WordPress plugins for using PayPal to pay a profit share or commission from your WooCommerce orders:

All of these plugins do largely the same thing. They all integrate PayPal Adaptive Payments with WooCommerce. They all split PayPal payments to multiple recipients using a choice of methods. These are Chained Payments, Parallel Payments or Standard Simple Payments. (Read the plugin documentation for definitions, as it's quite complicated.)

Although all 3 plugins looked fine and had quite good reviews, we chose the official WooCommerce extension. This is because it's safer to purchase plugins from a single company. WooThemes developed both WooCommerce itself and the PayPal Adaptive Payments plugin, so if we had any problems then they would have to take responsibility and couldn't blame the other developer. This is always a possibility when you combine plugins by multiple developers. Price-wise, the official plugin was the middle of the 3 options.

Our solution

We purchased the PayPal Adaptive Payments plugin and read the documentation, which was quite complex. Chained Payments was the best method for our client as it allows the commission to be automatically sent to our client's business partner without the customer knowing that this is happening.

We set up the plugin to work with WooCommerce products in a specific category only. The customer would pay via PayPal. It would look like their PayPal payment was going a single recipient. But behind the scenes, a 'Chained Payment' effect would kick in. A percentage of the payment was sent to our client's PayPal account and a different percentage was sent to her business partner. Perfect!

What's the catch?

The only downside is that PayPal Adaptive Payments are complicated. The fact that there's a plugin available doesn't make it easy to set up. We had to do a lot of fairly technical work to set everything up correctly. This included creating a PayPal App and submitting it to PayPal for approval. There were also several hoops to jump through such as providing PayPal with details of our client's business plan. (Because they wanted to check the payments were being used suitably.)

If you have a WordPress website and want Adaptive Payments, you'll probably need a WordPress web developer or agency to set it up. It's a great option if you want to automate more complex payment arrangements with PayPal.

WooCommerce shipping rates
WooCommerce is great and is the best plugin for most WordPress e-commerce websites. However its shipping options can be quite limited.

On the face of it, WooCommerce offers a good choice of delivery and shipping options - flat rate, free shipping, international flat rate, local delivery and local pickup.

Unfortunately this isn't as good as it looks for two reasons:

  • A lot of WordPress online shops need more granular control over their shipping rates - particularly if they ship to multiple countries or regions with different postage costs.
  • As it comes, WooCommerce only shows customers the shipping cost - or even whether you will ship to their country - on the checkout page. That's a disaster for WooCommerce stores that ship internationally! Customers get incredibly frustrated to add products to their cart and then discover that you either don't ship to their country, or that the shipping cost is too high.

Fortunately, there's an excellent solution to each of these problems:

  • Solution 1 - A lot of people add more flexible international shipping costs by using YITH's Product Shipping plugin
  • Solution 2 - The WooCommerce Shipping Calculator plugin lets customers check whether you ship to their country, and calculate the cost, directly on the product page. This is a super-simple way to avoid the frustration of getting bad news on the checkout. Either use it on its own or with YITH's plugin.

How to set up Flat Rate per State/Country/Region for WooCommerce

  1. Find the 'Flat Rate per State/Country/Region for WooCommerce 'plugin in the WordPress plugin repository. (Plugins → Add New in the WordPress admin for your website). Install and activate it as usual.
  2. Go to WooCommerce → Settings → Shipping in the WordPress admin. You will see that the plugin has added a new link to the right hand side of the list of shipping options: Flat Rate per State/Country/Region.
  3. Ignore all the information about which countries belong to different regions - you probably don't need this. Scroll down to the actual plugin settings and set up the plugin as required. It's pretty self-explanatory and you can hover over the question mark icons for an explanation of each option.

Note: If you use this plugin then it will control ALL your shipping options, replacing WooCommerce's built-in Flat Rate and International Flat Rate options. This means that you need to disable Flat Rate and International Flat Rate and use the 'Flat Rate per State/Country/Region' section to add ALL your postage costs, including your domestic shipping rate and the overseas shipping. If you forget to disable the other shipping options then they will appear as alternate shipping methods in the checkout.

Flat Rate per State/Country/Region for WooCommerce screenshotAn example of how to use the plugin

Although setting up this WooCommerce shipping plugin is fairly self-explanatory, here's a screenshot showing how to set it up to achieve the following scenario:

  • Shipping cost of $6.95 per order for the United States only (this example assumes that the website is based in the US).
  • Shipping cost of $15.00 for Canada.
  • Shipping cost of $22.50 for the rest of the world.

But what about shipping to individual countries within the UK?

TheFlat Rate per State/Country/Region for WooCommerce plugin is ideal for setting separate shipping rates for each country or region. However there are times when you want to break down your shipping zones further. For example you might want to charge different postage for England, Scotland and Wales - which WooCommerce treats as a single country (United Kingdom).

Since writing this post, WooCommerce has introduced shipping zones into its core plugin. This gives extra shipping options without needing any further plugins, so it's worth experimenting with. I've written a separate post about how to charge different shipping rates for each UK country.

Let customers calculate international shipping costs on the product page

Add shipping tab to WooCommerce product page

So far, you've learned how to solve the problem of not being able to add fine-grained shipping costs per country. The second problem was how to let customers check international shipping costs without having to add products to their cart first.

You can easily solve this by installing the WooCommerce Shipping Calculator plugin. This handy plugin adds a domestic or international shipping calculator to your chosen location on the product page. That way, customers can enter their country and see the shipping cost straight away. As a result, they can make an informed decision on whether to add it to their cart.

It's your turn

We've looked at two of the best WooCommerce shipping plugins:

I'd love to hear how you use them to improve how you charge for shipping per country. Please share your experiences in the comments below.

One of our WooCommerce clients recently asked how to prevent duplicate usernames. She wanted to know what would happen if a new customer creates an account on her WordPress e-commerce online shop and tries to add a username that is already in use.

WooCommerce has features built in to prevent duplicate usernames. Since so many websites use WooCommerce, I will describe the options to help anyone else who is worried about this.

Create username based on the user's email address

How to prevent duplicate usernames in WooCommerceIf you log into the WordPress admin and go to WooCommerce > Settings > Account, you can scroll down to a section called Registration Options. This allows you to tick a box called 'Automatically generate username from customer email'.

If you tick this box then when a customer creates an account during checkout, they will automatically be given a username based on the first part of their email address. Their username is not their actual email address, as most people assume. Instead, their username is the part of their email address which appears before the @. For example if my email is info@barn2.com then my username will be 'info'.

As you can see from this example, a lot of automatically generated usernames won't be very unique - how many people have info@ email addresses?! WooCommerce detects duplicate usernames and avoids the problem by adding a number after any duplicates. For example if I create an account when there is already a user called 'info' then my username will be 'info1'.

Many WooCommerce website owners aren't keen on this option because a lot of people like to choose their username to make it easy to remember. Fortunately there is another option.

Allow WooCommerce customers to choose a username

You can untick the 'Automatically generate username from customer email' box in WooCommerce > Settings > Account Registration Options. This adds a field to your checkout page prompting customers to choose their own email address.

If a customer enters an email address that has already been chosen, WooCommerce will prevent any duplicate usernames. Instead of adding a number after the username, an error message will appear after you click the 'Submit' button. This prompts the customer to choose a different email address.

Which option is best?

As always, there are pros and cons of each option.

Some WordPress website owners like the convenience of automatically generating usernames. This is attractive because it's one less field for the customer to fill in. Research into what makes an effective online form has reliably shown that the more information the customer is asked to enter, the less likely they are to complete the process. This is a big deal on a WooCommerce website as store owners need to prevent abandoned carts and checkouts.

But for overall user-friendliness, it's nice for customers to be able to choose a username that will be easy for them to remember in future.

The decision largely depends on the purpose of your customer accounts. If customers will have little reason to log into their account in future then it's best to automatically generate their username as this speeds up the checkout process. If you want to encourage repeat business, or if customers will be logging in for many different purposes (e.g. if you offer online courses or a membership area) then they're more likely to want an easy-to-remember username. Think about your customers and choose the best option for them.

Whilst making some small improvements to our website recently, I came across a small problem displaying a random post in WordPress.

Background

Our website has a custom post type called "Testimonials". We use to this to record our client testimonials which are then displayed in various places throughout our site. In addition to this, we wanted to display a random testimonial on the sidebar, so that each time a page loads a different testimonial is shown. Sounds simple, right?

First Steps - creating a shortcode

The first step was to write a new shortcode which I could drop into a standard text widget in our main sidebar. I called my shortcode [random_testimonial]. I won't go into the details of creating a WordPress shortcode - this has been covered a lot elsewhere and the Shortcode API is a good resource if you need more information.

The next step was to implement the shortcode to retrieve and display our random testimonial. This shortcode would run when each time the sidebar is displayed. If you were looking to display other types of content in your sidebar or footer, you could easily modify this example to get display a random post or page, for example.

Attempt 1

This was the code I tried first. I'd already assumed this would be the way to do it, and I saw similar variants mentioned in other articles and forums:

if ( post_type_exists( 'testimonial' ) ) { 
 
   $testimonial_query = new WP_Query( array(
       'post_type' => 'testimonial',
       'orderby' => 'rand',
       'posts_per_page' => 1
   ) );
 
   if ( $testimonial_query->have_posts() ) {
      $testimonial_query->the_post();     
 
      // do something with post - e.g. the_excerpt(), the_content(), etc.
   }
   // Restore original post data
   wp_reset_postdata();
}

However, this didn't work as expected. One first load, it seemed to select a testimonial at random, but on second, third and subsequent loads, the same testimonial was displayed each time.

After a couple of minutes head scratching, I realised the problem might be to do with the object and database caching on our server. Our site is hosted with WP Engine and the query above is exactly the sort of thing that would be cached by their highly efficient caching infrastructure.

So I needed to try another approach.

Attempt 2

global $post;

if ( post_type_exists( 'testimonial' ) ) { 
 
   $testimonial_query = new WP_Query( array(
       'post_type' => 'testimonial',
       'orderby' => 'rand',
       'posts_per_page' => -1
   ) );
 
   if ( $testimonial_query->have_posts() ) {
      $random_int = rand( 0, $testimonial_query->post_count - 1 );
      $post = $testimonial_query->posts[$random_int];     
      setup_postdata( $post );
      
      // do something with post - e.g. the_excerpt(), the_content(), etc.
   }
   // Restore original post data
   wp_reset_postdata();
}

And this time it worked as expected, loading a different testimonial on each page load.

The key here is returning all posts from the database ('posts_per_page' => -1) and then randomly selecting from the list of returned posts (i.e. testimonials). In this case, we only have 15 or so testimonials so it's not a big database hit, and the query will be cached. But if you're querying 1000's of blog posts, you might want to limit your query to say 50 or 100, or perhaps limit on a certain category.

Once we have our list, we create a random number between 0 and the maximum length of the list (subtracting 1 as the array is zero-indexed). We then select the random testimonial from the posts list on the WP_Query object ($post = $testimonial_query->posts[$random]) and then call setup_postdata() on that post. Once we've done this, we can then call our usual loop functions such as the_title(), the_content(), etc., remembering to call wp_reset_postdata() afterwards to restore the original query's post data.

Important note: Did you notice the global $post; line at the top of this code snippet? Well spotted. That's because we have to pass the global $post object to setup_postdata() for this to work. So the variable we assign our random testimonial to must also be called $post!

Wrapping up

Hopefully this tip was useful to you. Let me know if you have any questions in the comments.

Go liveSo you've designed a new WordPress website and it's ready to go live. Congratulations!

Going live is an important part of the web design process. Over the years, we have developed a detailed checklist of essential steps for launching a WordPress website. Read this checklist before you launch a website into the big wide world, and give it the best possible start.

1. Set the date

There's a right and a wrong time to go live. For some reason our clients always want to go live on a Friday. Bad idea!

Schedule the launch of the website for as early in the week as possible. This leaves the longest possible time to complete the go-live checklist and fix any teething problems before the weekend, when your WordPress web designer may not be available.

2. Move the WordPress website to its final location

Some people develop their WordPress website directly on their web host. If so, you can skip this step.

Others develop websites elsewhere, for example on a separate staging server or stored locally on their computer. This means that you'll need to arrange to move the finished website to your hosting account. This can take a while, so schedule it for at least a day or two before go-live.

Tip: If you haven't chosen a web host yet, we highly recommend WP Engine - the fastest, most reliable WordPress host we have ever worked with.

3. Final checks before going live

Our go-live checklist includes a few quality control checks to make sure we haven't missed anything during the WordPress web design process:

  1. Test everything on the website and ensure it's working correctly. Leave no stone unturned!
  2. Make a final check of the Settings section in the WordPress admin. Ensure things like the time zone are correct.
  3. If you're using an off-the-shelf WordPress theme with a child theme, make sure no custom CSS has been added in the theme options. Custom CSS should be either in the theme options or the child theme, but not both.
  4. Look at the Pages list in the admin and make sure all the pages are in the correct order. If there are lots of pages to re-order, consider a plugin such as Swifty Page Manager. This is worth doing even if you use custom menus and the order of pages isn't reflected on the public-facing website, as it makes it easier to work with the pages in future.
  5. Ensure there's no demo content from the theme still on the website - e.g. pages, posts, custom posts, media files.
  6. Go to Appearance > Themes, delete un-used themes and just keep the active theme (if you're using a child theme, you'll need to keep the parent and child theme) and the most recent default theme (e.g. TwentyFifteen).
  7. Make sure all contact forms, admin emails etc. are set to the correct address - the WordPress designer's email address will often be used during the development process, so don't forget to change this before go-live.
  8. Run the WP-Sweep plugin to remove all the page revisions etc. from the development phase. Delete this plugin afterwards.
  9. Make sure none of the images are more than approx. 1,920 pixels wide, or bigger if you are using retina images. Use the Imsanity WordPress plugin to bulk-resize them if needed. Leave this plugin active to resize any huge images that are accidentally uploaded in future.
  10. Use an image optimisation plugin such as WP Smush to bulk-optimise all the images on the site. Leave this plugin active if images will be added to the website in future.

4. Set up caching measures for improved page load times

Caching is an important way to speed up a WordPress website. Most people don't use caching during the development process because it can interfere with your work, for example by preventing you from seeing your changes straight away. This means that you need to set up caching immediately before the website goes live.

Caching is most effective when applied at hosting level. If your host doesn't offer caching, install a caching plugin.

  • If the site is hosted on WP Engine (our recommended WordPress web host), log into WP Engine and change the following settings:
    • CDN > Enable (this isn't caching, but it also boosts performance if it's available on your plan)
    • Utilities > Enable Object Caching
  • If the site is hosted on SiteGround (our recommendation for smaller or personal websites) or another company that provides caching - set up caching using the instructions from your web host.
  • Other hosting - install a caching plugin. Our favourite (if you're using an inferior web host that doesn't do their own caching!) is W3 Total Cache. To use it to its best effect, it ideally needs setting up by a WordPress professional as it requires quite a lot of knowledge to get right.

5. Set up automatic backups

Our recommended web hosts WP Engine and SiteGround have such good backups that we don't use backup plugins, unless a client has very specific requirements for storing backups. If you're using a web host with less good backups, or just want extra peace of mind, then it's worth adding a plugin.

Our favourite backup plugin is BackupWordPress and we also quite like BackWPup. For most websites, I'd recommend scheduling a weekly file backup and daily database backups. You will want more frequent backups if you're planning to make significant changes on a regular basis or if your website includes a lot of user-generated content.

Go through the settings for your backup plugin carefully and make sure it's not backing up anything non-essential such as the WordPress core and backup folders (don't backup your backups!). If you're running file and database backups at separate intervals, don't bother with a 'Full' backup as this will double up on other backups. Set your backups to auto-delete after a set period so they don't take up too much space.

The simplest option is to set your backups to save to a folder within your hosting account. For extra peace of mind (for example if anything happens to your web host), save your backups to a third party location such as a separate FTP account with a different host, Dropbox or Amazon storage.

Tip: Backup plugins use a lot more server resources than backups created directly on the server. This means that the website may slow down while a backup is being created using a plugin. Schedule the backups to take place in the middle of the night, and consider doing backups in some other way - particularly for very large websites.

6. Update your links

If you have been developing the website on a temporary URL, for example because your old website is still on your live domain, then you'll need to run a thorough 'search and replace' script to update all the links. Backup the database first in case anything goes wrong, then do a search and replace to replace all instances of the temporary URL with the finished URL.

Be aware that once you have done a search and replace, the website probably won't function correctly until you have updated the settings for the domain name (see step 7).  This is because the website is pointing to the final domain but the domain isn't yet pointing to it. Don't worry about this - you should already have tested the website in step 3. If you have done the search and replace correctly, things should start working properly as soon as the domain settings update.

Tip: There are lots of different methods for running a search and replace script. If you do it by installing a PHP file on the server, ALWAYS remember to delete this immediately afterwards - this is really important for security.

7. Update the domain name

If you have been developing the website on the actual domain name then you can skip this step.

If you have been using a temporary URL - for example because the domain is currently pointing at the old website - then you will need to update the domain name to point to the new website.

You can set the nameservers to your web host, but this method isn't suitable if you use your domain name for anything else, for example if you use a different host for your email or if you have separate subdomains. The best method is to go into the Advanced DNS for your domain name and update the following records to use the IP address where the website is hosted:

    • The root A record (this is usually indicated by a * or www)
    • The WWW A record

Note: Domain name settings are very complicated and if you don't know what you're doing, I recommend that you speak with your domain name register, your web host or a WordPress web designer. The above is a very basic guide and won't apply to all scenarios.

8. Wait!

If you have updated the nameservers in step 7 then the changes can take up to 48 hours to take effect. The changes populate slowly across the internet, so there might be a strange interim period where customers can see the old website (if you have one) and you can see the new one, or vice versa!

If you used Advanced DNS to update the domain then this usually happens quite quickly, depending on the domain name registrar - usually within a few hours although there are no guarantees. If you can see a field called 'TTL' in the Advanced DNS, try to decrease this to the smallest number it will accept - this means 'Time 'Till Live' and affects the length of time before the changes will take effect.

Please be patient - this stage is frustrating when you're excited about the new website going live. Unfortunately there's nothing you can do to speed it up.

9. URGENT! Unblock the website from search engines

As soon as the website goes live, log into the admin, go to Settings > Reading and untick the 'Discourage search engines' box. (I sincerely hope this was ticked during the development process!)

10. Submit to search engines

You should also submit the website to search engines, whether it's a new site or a redesign of an existing website. This encourages the main search engines to crawl the new website as soon as possible to index the new content.

11. Set up Google Analytics

Google Analytics is a powerful tool to track how many people are visiting the website and how they are interacting with it. In my experience, nearly all WordPress websites will benefit from having Google Analytics or a similar tool installed. This should be done as soon as the website goes live on the final domain.

  1. Log into Google Analytics and add the website as a new Property
  2. Install and set up the Google Analytics for WordPress plugin

Tip: I recommend using the above method even if the theme has a 'Google Analytics Tracking Code' box. This is because using a separate Analytics plugin means that you won't lose your tracking code if you ever switch theme.

12. Set up Google Webmaster Tools

Log into Google Webmaster Tools and add both the www and non-www versions (e.g. www.barn2.com and barn2.com) so that you can tell Google which is your preference. Verify it using your Google Analytics account, which you just set up in the previous step.

Look at the information in Google Webmaster Tools to make sure Google is able to crawl the site correctly. Fix any problems that are reported. (Webmaster Tools will also email you if it detects any major problems in future.)

Other search engines have their own version of Webmaster Tools which are specific to them. Our go-live process only includes Google Webmaster Tools because Google is the main search engine and the issues they are having will be relevant to other search engines too.

13. After go-live - Building traffic and keeping the website running smoothly

Once the new WordPress website has gone live, I hope you feel proud and start receiving positive feedback. But there's no time to relax - there's still lots of work to do! You need to build traffic to the website and keep it properly maintained.

Ongoing SEO

Your WordPress website may look beautiful, but it will only achieve its aims if enough people are visiting it. A good ongoing SEO (search engine optimisation) strategy is essential for this, in conjunction with effective social media marketing and adding regular content to the website.

Software and security updates

Within a few days of going live (I'm not exaggerating!), most WordPress website owners will start to see updates becoming available in Dashboard > Updates.

It's really important to keep WordPress itself, the theme (if you're using an off-the-shelf theme) and plugins on the website up to date. This is the main thing you can do to protect the website from hacking. It will also make sure your website is compatible with new versions of WordPress that are released in future. When WordPress is updated, theme and plugin authors usually release an update to achieve this so it's important to install them. This is especially important for websites with complex plugins such as e-commerce and membership.

Some WordPress web hosts will update WordPress automatically for you. This is great, but you're still responsible for updating the theme and plugins.

Future developments to your WordPress website

A well designed WordPress website should be able to grow with your company. Don't let it go out of date - keep the content fresh and add new pages and features over time. This will help it to achieve its potential so that it keeps working for you, both immediately after go-live and into the future.