Skip to content

Instantly share code, notes, and snippets.

@AchalJ
Last active October 8, 2022 01:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AchalJ/0337767c92820b4169fb2a7f7d184706 to your computer and use it in GitHub Desktop.
Save AchalJ/0337767c92820b4169fb2a7f7d184706 to your computer and use it in GitHub Desktop.
PP Taxonomy Term - Custom Shortcode to get term image URL
<?php // ignore this
// Copy the code below to your current theme's functions.php file.
// Uses: [get_term_image_url] or [get_term_image_url term_id="PROVIDE TERM ID HERE"]
add_shortcode( 'get_term_image_url', function( $atts ) {
$term_id = 0;
if ( isset( $atts['term_id'] ) && ! empty( $atts['term_id'] ) ) {
$term_id = $atts['term_id'];
} else {
$queried_object = get_queried_object();
// Maybe term archive.
if ( is_object( $queried_object ) && isset( $queried_object->term_id ) ) {
$term_id = $queried_object->term_id;
}
}
$id = get_term_meta( $term_id, 'taxonomy_thumbnail_id', true );
$image = wp_get_attachment_image_src( $id, $settings->size );
$url = ! empty( $image ) ? $image[0] : '';
return $url;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment