You appear to be a bot. Output may be restricted
Description
Return an image pulled from the media gallery.
Supported $args keys are:
– format – string, default is 'html' – size – string, default is 'full' – num – integer, default is 0 – attr – string, default is '' – fallback – mixed, default is 'first-attached'
Applies genesis_get_image_default_args`,
filters. genesis_pre_get_image
and `genesis_get_image
Usage
$string|bool = genesis_get_image( $args );
Parameters
- $args
- ( array|string ) optional – Optional. Image query arguments. Default is empty array.
Returns
string|bool Return image element HTML, URL of image, or `false`.
Source
File name: genesis/lib/functions/image.php
Lines:
1 to 72 of 72
function genesis_get_image( $args = [] ) { $defaults = [ 'post_id' => null, 'format' => 'html', 'size' => 'full', 'num' => 0, 'attr' => '', 'fallback' => 'first-attached', 'context' => '', ]; /** * A filter on the default parameters used by `genesis_get_image()`. * * @since unknown */ $defaults = apply_filters( 'genesis_get_image_default_args', $defaults, $args ); $args = wp_parse_args( $args, $defaults ); // Allow child theme to short-circuit this function. $pre = apply_filters( 'genesis_pre_get_image', false, $args, get_post() ); if ( false !== $pre ) { return $pre; } // If post thumbnail (native WP) exists, use its id. if ( 0 === $args['num'] && has_post_thumbnail( $args['post_id'] ) ) { $id = get_post_thumbnail_id( $args['post_id'] ); } elseif ( 'first-attached' === $args['fallback'] ) { // Else if the first (default) image attachment is the fallback, use its id. $id = genesis_get_image_id( $args['num'], $args['post_id'] ); } elseif ( is_int( $args['fallback'] ) ) { // Else if fallback id is supplied, use it. $id = $args['fallback']; } // If we have an id, get the HTML and URL. if ( isset( $id ) ) { $html = wp_get_attachment_image( $id, $args['size'], false, $args['attr'] ); list( $url ) = wp_get_attachment_image_src( $id, $args['size'], false ); } elseif ( is_array( $args['fallback'] ) ) { // Else if fallback HTML and URL exist, use them. $id = 0; $html = $args['fallback']['html']; $url = $args['fallback']['url']; } else { // No image. return false; } // Source path, relative to the root. $src = str_replace( home_url(), '', $url ); // Determine output. if ( 'html' === mb_strtolower( $args['format'] ) ) { $output = $html; } elseif ( 'url' === mb_strtolower( $args['format'] ) ) { $output = $url; } else { $output = $src; } // Return false if $url is blank. if ( empty( $url ) ) { $output = false; } // Return data, filtered. return apply_filters( 'genesis_get_image', $output, $args, $id, $html, $url, $src ); }