Skip to content

Snippet: Multi-Post Thumbnails Plugin Usage Example

This is a guide for using the Multi-Post thumbnails plugin with Total. This will allow you to set a secondary image specifically for your entries so you can have one image for the entry and one for the post. Of course you can use different code to alter the post image instead - simply alter where it says "wpex_blog_entry_thumbnail_args" to say "wpex_blog_post_thumbnail_args"

// Example function showing how to make use of the Multi-Post Thumbnails plugin
// To display a secondary image on your single posts
// This is just a basic example you can do much more then this ;)
function myprefix_blog_entry_thumbnail_args( $args ) {

    // Your secondary image ID
    $secondary_image_id = 'secondary-image'; // NOTE: tweak this to match your ID
    $secondary_image_meta_key = get_post_type() .'_'. $secondary_image_id .'_thumbnail_id';

    // Get your second image and if it exists update the attachment param
    // Note: Only if attachments is currently empty to prevent issues with sliders
    if ( empty( $args['attachment'] )
        && $secondary_image = get_post_meta( get_the_ID(), $secondary_image_meta_key, true )
    ) {
        $args['attachment'] = $secondary_image;
    }

    // Return args
    return $args;

}
add_filter( 'wpex_blog_entry_thumbnail_args', 'myprefix_blog_entry_thumbnail_args' );
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