gtaxi_get_taxonomy_image( array $opts = array() )
Retrieves the image assigned to a term via the Genesis Taxonomy Images plugin.
Parameters
$opts
(array)(Optional) The array of options telling gtaxi_get_taxonomy_image()
what to retrieve.
The array can contain any of the following:
format
(string) The format to retrieve.
html
creates a full HTML markup including srcset;url
orsrc
gets just the image url;id
gets the image ID. This is the same as just usingget_term_meta()
Default is html
size
(string) Any built-in or user-defined media size. If missing or invalid, full
is used.
Default is full
attr
(string|array) Attributes applied to the requested image html. This is passed through to wp_get_attachment_image()
so see its API page for details.
Default is empty
fallback
(string) What to return if no term image is assigned.
placeholder
will return the default image in the requested format except for ID, which will return null (because there is no ID for the default image);- Anything else will return null.
Default is placeholder
term
(WP_Term|int) Term object or term ID.
Default is the term taken from the main query.
Examples
This example shows the default usage, which will get the full HTML for the image assigned to the current term, or the HTML for the default image.
$url = gtaxi_get_taxonomy_image();
This is the same as the above, except for a specific term. Note that you can supply either a term object or term ID.
$url = gtaxi_get_taxonomy_image( array(
'term' => 123,
) );
This one will get only the URL, and return nothing if an image is not set.
$url = gtaxi_get_taxonomy_image( array(
'format' => 'url',
'fallback' => ''
) );
You can use this function with the many actions and filters that come with genesis to put the image out for a term wherever you like.