Skip to content

Post Thumbnail Helper Functions

The Total theme has a built-in image resizing function that crops images only as needed instead of the core WordPress post thumbnail function which crops images to every defined size whenever you upload a new image. For this reason Total has it’s own helper functions for returning images in the theme which you can make use of in your child theme if needed/wanted.

Here is an example:

$thumbnail = wpex_get_post_thumbnail( [
	'post'           => null,    // (int) Fetch thumbnail from a post.
	'attachment'     => '',      // (int) Fetch thumbnail from a specific attachment ID.
	'size'           => '',      // (string) Pre-defined thumbnail size name (thumbnail, medium, full).
	'width'          => '',      // (int) Custom width.
	'height'         => '',      // (int) Custom height.
	'crop'           => '',      // (int/string) Crop location.
	'return'         => 'html',  // (string) Function return html, url, src.
	'style'          => '',      // (string) Custom inline style attributes (padding:10px;).
	'alt'            => '',      // (string) Custom alt.
	'class'          => '',      // (string) Custom classnames.
	'before'         => '',      // (html/string) Content to add before the thumbnail.
	'after'          => '',      // (html/string) Content to add after the thumbnail.
	'attributes'     => array(), // (array) Custom html attributes.
	'add_image_dims' => true,    // (bool) Add width/height attributes?
	'schema_markup'  => false,   // (bool) Add schema markup?
] );

More helper functions:

Below is a table showing other helper functions available in the theme.

Function NameParametersDescription
wpex_get_post_thumbnail_srcArray $argsSame as the above function but returns the src without having to set the return parameter.
wpex_get_thumbnail_sizes-Returns an array of all registered image sizes
wpex_featured_image_captionInt $post_idReturns the caption for the current post featured image.
wpex_get_attachment_dataInt $attachment_id
string $return
Returns data (url, src, alt, title, caption, description or video) for the given attachment id. If no $return value is provided it will return an array of all data.
wpex_get_lightbox_imageInt $attachment_idReturns the lightbox url for the given attachment id.
wpex_placeholder_img_src-Returns the theme's placeholder image.
Back To Top