How To Create Testimonials In WordPress With Custom Post Types

If you sell products or services online, then you must have a testimonials page on your website to show off some customers review of your service. Your customers can benefit you by giving you feedback of your work, which will boost your sales as well.

Let me show how you can create testimonials in WordPress with custom post types. Adding testimonials will be just like writing a post with all the details. This tutorials comes from Tuts+. Let’s get started.

Creating Custom Post Type

First we will create a custom post type for testimonials with archive. You can add following code to your current theme’s functions.php file or in a custom plugin:

Now that our custom post type has been created, we will add some metaboxes to the post type using add_meta_box() and will save the metabox values with save_post action:

After creating the custom post type, we will add few more functions to finish the code:

That’s pretty much it with custom post type. Now you can see an option to create and edit testimonials in your WordPress’ sidebar. Now, I’ll show how you can display there testimonials in the front-end of your website.

Display Testimonials Using Shortcode

That’s the easiest way to display your testimonials. You can display your testimonials using a simple [testimonials] shortcode. Just add following code:

That’s it! But wait, there’s another trick to display testimonials post type.

Display Testimonials Archive Page Template

As we have created a custom post type with archive, we can show the testimonials on the archive with a custom template. Create a file called archive-testimonials.php and add it to your current theme’s root with following code:

That’s it! You can now proudly show off some great client testimonials on your WordPress website. You can also add some CSS to style the testimonials:

Yea, that’s wrap!