dozent_get_course_thumbnail( int $post_id, string $size = 'medium', bool $url = false )

Get the course thumbnail


Description

If the course thumbnail is not attached with the course (Post), it will show a placeholder. This function return the HTML instead of echo directly

Example usage:

dozent_get_course_thumbnail();

Parameters

$post_id

(int) (Required) Post ID | Course ID

$size

(string) (Optional) Thumbnail Size

Default value: 'medium'

$url

(bool) (Optional) if return only url instead of structured HTML

Default value: false


Return

(false|string)


Source

File: includes/template-functions.php

1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
function dozent_get_course_thumbnail( $post_id = 0, $size = 'medium', $url = false ) {
 
    $post_id           = dozent_get_post_id( $post_id );
    $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id );
 
    if ( $post_thumbnail_id ) {
        $size = apply_filters( 'dozent_course_thumbnail_size', $size, $post_id );
        if ( $url ) {
            return wp_get_attachment_image_url( $post_thumbnail_id, $size );
        }
 
        $html = wp_get_attachment_image( $post_thumbnail_id, $size, false );
    } else {
        $placeHolderUrl = DOZENT_URL . 'assets/images/placeholder.svg';
        if ( $url ) {
            return $placeHolderUrl;
        }
        $html = sprintf( '<img alt="%s" src="' . $placeHolderUrl . '" />', __( 'Placeholder', 'dozent' ) );
    }
 
    return $html;
}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.