Total Cards are used to display post entries within grids and archives and while there are a many pre-build cards to choose from sometimes you may want to create a custom card design and luckily the WPEX_Card API makes it super easy!
Since Total 5.5 you can create custom Cards via Theme Panel > Custom Cards using your favorite page builder (WPBakery, Gutenberg or Elementor). This guide explains how to create custom cards using your child theme; ideal for more advanced designs or if you prefer not to use a page builder.
Creating custom Card styles in your child theme is quite simple, below you will find how to register your card styles and how to actually code your own custom styles.
Step 1: Register Your Custom Cards
First thing you need to do is register your custom cards so that the theme knows they exist. Registering your cards is done by hooking into the “wpex_card_styles” like the example below:
/**
* Register custom card styles.
*
* @link https://totalwptheme.com/docs/how-to-create-custom-theme-cards/
*/
add_filter( 'wpex_card_styles', function( $card_styles ) {
$my_cards = [
'my-card-2' => [
'name' => esc_html__( 'My Card 1', 'Total' ),
'template' => get_stylesheet_directory() . '/my-cards/my-card-2.php',
'group' => esc_html__( 'My Cards', 'Total' ),
],
'my-card-2' => [
'name' => esc_html__( 'My Card 2', 'Total' ),
'template' => get_stylesheet_directory() . '/my-cards/my-card-2.php',
'group' => esc_html__( 'My Cards', 'Total' ),
],
];
return array_merge( $my_cards, $card_styles );
} );

It’s best to give your custom cards unique names to avoid conflicts with the theme. For instance, if you create a custom card called blog-40.php and the theme later introduces a card with the same name, your version would override the theme’s file.
If you’re organizing your cards within folders, be sure to give those folders unique names as well to prevent potential naming conflicts. A simple way to do this is by using a prefix. For example, naming your folder mysite-blog is a good way to keep your custom blog card styles distinct.
Step 2: Create Your Custom Card Files
Now that you have registered your custom cards you will need to create your card templates. When creating your card output you can use the theme’s WPEX_Card API (accessible via the $this variable) or using any code you want.
Your Card template file supports standard PHP and HTML so you can literally add anything you want in your template.
Sample Card (based on Blog 22)
<?php
defined( 'ABSPATH' ) || exit;
$has_link = $this->has_link_wrap();
$html = '';
if ( $has_link ) {
$html .= $this->get_link_open( [
'class' => 'wpex-card-inner wpex-flex wpex-flex-col wpex-flex-grow wpex-overflow-hidden wpex-rounded-md wpex-border wpex-border-solid wpex-border-main wpex-surface-1 wpex-no-underline wpex-inherit-color',
'attributes' => array(
'aria-label' => get_the_title( $this->post_id ),
),
] );
} else {
$html .= '<div class="wpex-card-inner wpex-flex wpex-flex-col wpex-flex-grow wpex-overflow-hidden wpex-rounded-md wpex-border wpex-border-solid wpex-border-main wpex-surface-1">';
}
$html .= $this->get_media( [
'link' => ! $has_link,
] );
$html .= '<div class="wpex-card-details wpex-flex wpex-flex-col wpex-flex-grow wpex-p-30 wpex-last-mb-0">';
$html .= $this->get_title( [
'class' => 'wpex-heading wpex-child-inherit-color wpex-text-xl',
'link' => ! $has_link,
] );
$html .= $this->get_excerpt( [
'class' => 'wpex-mt-15',
] );
$html .= '</div>';
if ( $has_link ) {
$html .= $this->get_link_close();
} else {
$html .= '</div>';
}
return $html;
As you can see, all cad methods reference $this which is is the card object of WPEX_Card type. You can find the class at Total/inc/lib/wpex-card.php.
Displaying Content
The Card API offers several methods for displaying content, all of which work in a similar way. However, you can also use core WordPress functions if you prefer. Since a custom card is simply a PHP file, you can include any PHP or HTML code you like within it. Just make sure to return your code from the card, rather than echoing it.
While passing arguments isn’t required, you’ll typically want to include a class parameter to apply your own custom styles. In the example above, we’ve used the theme’s CSS utility classes (those prefixed with wpex-) to handle the card’s design. This way you don’t need to target it with custom CSS.
WPEX_Class Methods
Below is a table with available class methods:
| Method | Description |
|---|---|
get_element | Global method for displaying any content. Simply pass a content key as the argument with the content to return |
get_media | Displays the post featured image, video or audio. |
get_thumbnail | Display the post featured image. |
get_video | Display the post featured video. |
get_audio | Display the post featured audio. |
get_icon | Display the post icon defined in the Card Settings metabox. |
get_title | Display the post title. |
get_date | Display the post published, updated or event date. |
get_time | Display the post published, updated or event time. |
get_author | Display the post author name. |
get_excerpt | Display the post excerpt – custom or auto generated. |
get_more_link | Displays a link to the post. |
get_terms_list | Displays a list of assigned post terms: category, tag or custom taxonomy. |
get_primary_term | Displays the primary term (Yoast SEO) or first term: category, tag or custom taxonomy. |
get_number | Displays the post number as displayed in the Post Card, for example the second entry will display a 2. |
get_star_rating | Display the post rating as defined in the themes custom field – testimonials. |
get_custom_field | Displays the raw value of a custom field – you must pass a ‘key’ => ‘custom_field_name’ argument. |
WPEX_Class Method Parameters
Below is a list of common parameters that can be used in any of the methods mentioned above:
| Parameter | Type | Description |
|---|---|---|
name | string | If given a name will be added to the containing div as wpex-card-{name} |
class | string | Custom classes for the element |
content | string | The content to display in the element (used for the get_element method0) |
link | bool/string | Adds a link around the element, if you set a custom url it will use that instead |
link_class | string | Custom link class |
link_rel | string | Custom link rel |
link_target | string | Custom link target |
sanitize_content | bool | Whether to sanitize the output or not passes through wp_kses_post |
html_tag | string | HTML tag for your element |
before | string | Insert extra content before your element |
after | string | Insert content after your element |
icon | string | Icon classname to add before, example: “ticon ticon-bolt” |
prefix | string | Extra content added added before the element content inside element div |
suffix | string | Extra content added added after the element content inside element div |
css | string | Inline CSS example: color:white;background:red; |
data | string | Custom data attributes to attach to the element div |
overlay | string | Theme overlay style name to add to the element for images |
Card Arguments
Whenever a card is displayed, it comes with a set of arguments that can be modified dynamically as needed. You can find the full details and options in the documentation here.