Timeline Express comes bundled with CMB2, which is a framework for quickly spinning up custom metaboxes for posts, pages, options pages and more.

Alongside the CMB2 metabox framework, we’ve built in a number of hooks and filters to allow our users to assign new metaboxes and meta fields to the announcement pages – without having to touch the core code. This ensures that with each update to Timeline Express, any and all customizations will remain intact.

Knowing that CMB2 comes bundled with Timeline Express allows you to expand upon the base plugin to generate custom fields that are not otherwise available to you.

Adding Custom Metafields

The following snippet allows you to quickly and easily generate new meta fields for your announcements.

 * Timeline Express Add Custom Metabox
 * @param  array $options Array of options for Timeline Express.
function define_custom_excerpt_metabox( $options ) {
    $announcement_custom_metabox = new_cmb2_box( array(
        'id'            => 'custom_meta',
        'title'         => __( 'Announcement Custom Excerpt', 'text-domain' ),
        'object_types'  => array( 'te_announcements' ), // Post type
        'context'       => 'advanced',
        'priority'      => 'high',
        'show_names'    => true, // Show field names on the left
    ) );
    // Container class
    $announcement_custom_metabox->add_field( array(
        'name' => __( 'Custom Excerpt', 'text-domain' ),
        'desc' => __( 'Enter the custom excerpt for this announcement in the field above.', 'text-domain' ),
        'id'   => 'announcement_custom_excerpt',
        'type' => 'wysiwyg',
    ) );
add_action( 'timeline_express_metaboxes', 'define_custom_excerpt_metabox' );

It’s important to note that CMB2 comes bundled with a number of field types, so if the WYSIWYG doesn’t suit your needs – you can easily swap out that field type for another. Take a look at the CMB2 Field Types Documentation for a complete list of field types.

Displaying the Metadata

When you’ve generated the necessary fields for your announcements, you’ll want to display the new meta data on the front end of your site – either on the timeline or on the single announcement page.

Since the metadata gets stored as post meta, we can use the built in function get_post_meta() to retrieve the data as needed. The following function will retrieve the content of the meta field we created above ‘custom_meta’.

// Only display the custom excerpt field if it set
echo ( get_post_meta( $post->ID, 'announcement_custom_excerpt', true ) ) ? get_post_meta( $post->ID, 'announcement_custom_excerpt', true ) : '';


// Only display the custom excerpt field if it set
if ( get_post_meta( $post->ID, 'announcement_custom_excerpt', true ) ) {
   echo get_post_meta( $post->ID, 'announcement_custom_excerpt', true );

Which can be used in any of the template files bundled with Timeline Express.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.