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
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
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |