Skip to content

Snippet: Enable Video Support for Cards

You can now enable videos for cards when displaying posts via the Post Cards element under the Media tab. This snippet is primarily for targeting auto archives or changing things globally.

By default theme cards only display thumbnails and not other media such as videos or galleries. The following snippet can be used to enable video support for your cards.

Important: This won't automatically display videos since not all card styles are coded to support them, but it will enable video display for cards using the get_media() card method (see the WPEX_Card API).

/**
 * Enable Video support for Cards.
 *
 * @link https://total.wpexplorer.com/docs/snippets/cards-video-support/
 */
add_filter( 'wpex_card_allowed_media', function( $media ) {
    if ( is_array( $media ) && ! in_array( 'video', $media ) ) {
        $media[] = 'video';
    }
    return $media;
} );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top