How to Create a Custom Testimonial Shortcode for ElegantThemes in WordPress

While customizing my WordPress template, I came across an interesting new feature called the “Testimonial Shortcode” that comes with themes developed by ElegantThemes.
I was fascinated by this feature, but I noticed one limitation — it lacks flexibility. Every time you want to add a new testimonial, you have to manually edit the page or post that contains the shortcode.

This tutorial is intended for WordPress developers and intermediate users who are using an ElegantThemes template and have some knowledge of PHP and WordPress programming.

What Are Shortcodes and Custom Post Types?

Before we dive into coding, let’s review what shortcodes and custom post types are.

What Is a Shortcode?

A shortcode is a WordPress-specific tag that lets you perform powerful functions with minimal code.
Shortcodes can embed files or create objects that would otherwise require complex programming — all in one line of code.

Example:
<code>[shortcode_name]</code>

In short: shortcode = shortcut.

What Is a Custom Post Type?

A custom post type allows you to add new kinds of content to your WordPress site beyond the default “posts” and “pages.”
For instance, you might create custom post types for “Testimonials,” “Portfolio Items,” or “Events.”

In this tutorial, we’ll create a custom post type called “Testimony.”

Step 1: Register a Custom Post Type

First, we’ll create the custom post type.
You can place the following code in your functions.php file inside your theme directory.

/**
 * Register Custom Post Type: Testimony
 */
function register_testimony_post_type() {
	$labels = array(
		'name'                  => __( 'Testimony', 'yourtheme' ),
		'singular_name'         => __( 'Testimony', 'yourtheme' ),
		'add_new'               => __( 'Add Testimony', 'yourtheme' ),
		'add_new_item'          => __( 'Add New Testimony', 'yourtheme' ),
		'edit_item'             => __( 'Edit Testimony', 'yourtheme' ),
		'new_item'              => __( 'New Testimony', 'yourtheme' ),
		'view_item'             => __( 'View Testimony', 'yourtheme' ),
		'search_items'          => __( 'Search Testimony', 'yourtheme' ),
		'not_found'             => __( 'No testimony created', 'yourtheme' ),
		'not_found_in_trash'    => __( 'No testimony found in trash', 'yourtheme' ),
	);

	$args = array(
		'labels'                => $labels,
		'public'                => true,
		'show_ui'               => true,
		'can_export'            => true,
		'_builtin'              => false,
		'_edit_link'            => 'post.php?post=%d',
		'capability_type'       => 'post',
		'hierarchical'          => true,
		'rewrite'               => array(
			'slug' => 'testimony',
		),
		'query_var'             => 'testimony',
		'supports'              => array(
			'title',
			'editor',
			'author',
			'excerpt',
			'thumbnail',
			'comments',
			'trackbacks',
			'revisions',
			'page-attributes',
		),
		'menu_position'         => 7,
		'show_in_nav_menus'     => true,
	);
	register_post_type( 'testimony', $args );
}
add_action( 'init', 'register_testimony_post_type' );

Step 2: Customize the Admin Columns

To make the “Testimony” post type easier to manage in the WordPress admin panel, add this code to modify the columns.

add_filter( 'manage_edit-testimony_columns', 'custom_edit_testimony_columns' );
function custom_edit_testimony_columns( $columns ) {
	$columns = array(
		'cb'      => '',
		'title'   => 'Author Name',
		'content' => 'Testimony',
	);

	return $columns;
}

add_action( 'manage_testimony_posts_custom_column', 'custom_manage_testimony_columns', 10, 2 );
function custom_manage_testimony_columns( $column, $post_id ) {
	global $post;

	switch ( $column ) {
		case 'content':
			$content = et_content_helper( $post->post_content );
			echo esc_html( $content );
			break;

		default:
			break;
	}
}

add_filter( 'manage_edit_testimony_sortable_columns', 'custom_testimony_sortable_columns' );

function custom_testimony_sortable_columns( $columns ) {
	$columns['content'] = 'Testimony';
	return $columns;
}

Step 3: Create the Shortcode

Now, we’ll create a shortcode called “custom_testimonial” that dynamically retrieves all “Testimony” posts and outputs them using ElegantThemes’ built-in testimonial shortcode.

Add the following code to your functions.php file:

<?php
/**
 * Generate custom testimonials shortcode output
 */
function custom_testimonial_generator() {
	$testimonial_query = new WP_Query(
		array(
			'post_type'      => 'testimony',
			'posts_per_page' => -1, // optional: get all testimonials
		)
	);

	if ( $testimonial_query->have_posts() ) {
		while ( $testimonial_query->have_posts() ) {
			$testimonial_query->the_post();

			$content = et_content_helper( get_the_content() );
			$author  = get_the_title();
			$company = get_post_meta( get_the_ID(), 't_company', true );

			$thumbnail_id = get_post_thumbnail_id( get_the_ID() );
			$image_url    = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail' );
			$image        = ! empty( $image_url[0] ) ? $image_url[0] : '';

			echo do_shortcode(
				sprintf(
					'[tstimonial author="%s" company="%s" image="%s"]%s[/tstimonial]',
					esc_attr( $author ),
					esc_attr( $company ),
					esc_url( $image ),
					$content
				)
			);
		}
	}

	wp_reset_postdata();
}

Step 4: Use the Shortcode in a Page or Post

Finally, you can display all your testimonials on any page or post by inserting the following shortcode:

<code>[custom_testimonial]</code>

That’s it!
This shortcode will automatically display all your custom testimonials using ElegantThemes’ testimonial format.

Conclusion

By creating a custom post type and a custom shortcode, you can easily manage and display testimonials without manually editing each page.
This approach gives you more flexibility, organization, and control over your website’s testimonial section.

Hope you find this tutorial helpful and that it helps you make better use of ElegantThemes’ testimonial shortcode feature.

Improve Your Site With These Website Design Secrets

Your website should include a prominently displayed tagline. Your tagline lets others know more about you or your business. Using a tagline that’s clear can really help because if someone goes to your site, it takes about eight seconds to get their attention so they’ll be interested in your page.

Make sure you give your users the option to cancel a given action if they choose to. An action may refer to signing up for e-mail notifications, newsletter subscriptions or filling out web forms. Forcing your user to complete an action they don’t wish to will ensure they never sign up for anything on your site again, nor are they likely to return at all.

Do not go overboard in using lots of fonts when creating your website. You need to also be mindful of how some fonts appear on monitors, since smaller serif fonts are difficult to read. A lot of sites use Verdana since it isn’t hard to read when it’s any color or size.

Search Engines

You don’t want to be using frames when you are optimizing your website. While they improve your site’s looks, any information contained in a frame is not indexed by search engines. Your rating will not be very high if search engines can’t see some of your important info. When there is a low rating, there is little traffic.

Make sure that your site is optimized for previous editions of Internet Explorer. Many people still use old IE versions. They often don’t render elements to web standards, so you will have to work around them. An example would be the vexing “box model bug” which troubled IE for quite some time.

Meta tags are key to your site if you want to attract people to your site for short and long periods of time. Make sure you include them. Having some meta tags that offer quality will be able to help show different search engines what your site is all about. If you do not have good meta tags that describe your site well, you are not going to attract many visitors to your site.

You should now have a great start on the basics of website design and feel a little less confused by it. Now that you feel more comfortable with the subject, you can use this information and apply it to your web page design to reach you goals.

How to send email with your own domain using Gmail

Many business owners want to maintain a professional image by sending emails from their custom domain (like [email protected]). Fortunately, Gmail allows you to combine the professionalism of a branded email with its familiar interface and powerful features. In this guide, you will learn step-by-step how to set up Gmail to send emails from your own domain, including screenshots and SMTP configuration tips.

Why Use Gmail with Your Own Domain?

Using Gmail with a custom domain offers several advantages. First, emails appear from your domain, which helps build trust with clients. Additionally, you can continue using Gmail’s intuitive interface, including labels and filters. Moreover, managing multiple accounts becomes easier because everything is centralized in one inbox. Finally, Gmail provides built-in security features like spam filtering and two-factor authentication, keeping your email safe and reliable.

Step 1: Access Gmail Settings

To begin sending emails from your custom domain, you need to access Gmail’s settings. Start by opening Gmail and clicking the gear icon in the top-right corner. Then, select See all settings. After that, go to the Accounts and Imports tab to proceed.

  1. Open Gmail and click the gear icon in the top-right corner
  2. Select See all settings.
  3. Go to the Accounts and Imports tab.

Step 2: Add Your Custom Email Address

  1. Under the “Send mail as” section, click Add another email address.
  2. A popup will appear. Enter your name and custom email address.
  3. Make sure “Treat as an alias” is checked and click Next Step.

Step 3: Configure SMTP Server

  1. Enter your SMTP server, username, and password.
    • Usually, the username is your full email address.
    • SMTP details are provided by your hosting provider; check Google Workspace SMTP settings if needed.
  2. Click Add Account.

Step 4: Verify Your Email Address

  1. Gmail will send a verification email to your custom email.
  2. Open the email and click the verification link. Once verified, your Gmail account can now send emails using your own domain.

Benefits of Using Gmail with Your Own Domain

  • Professional branding: Emails come from your domain, improving credibility.
  • Gmail interface: Continue using Gmail’s intuitive interface, labels, and filters.
  • Centralized inbox: Manage multiple accounts in one place.

Additional Tips

  • Checkout how out other article to improve email deliverability
  • If you’re using WordPress, consider linking your custom email to WP Mail SMTP for reliable delivery.
  • Ensure your domain has proper SPF, DKIM, and DMARC records set up to prevent emails from landing in spam.

If you find this guide helpful, please don’t hesitate to click the like button below or share it with friends!