Skip to content

Instantly share code, notes, and snippets.

@Firsh
Last active January 1, 2022 17:50
Show Gist options
  • Save Firsh/ce106636ef9a54ceb9ca73559aa5e477 to your computer and use it in GitHub Desktop.
Save Firsh/ce106636ef9a54ceb9ca73559aa5e477 to your computer and use it in GitHub Desktop.
JIG show (custom) taxonomy terms as image title
<?php
add_filter('jig_images', 'change_jig_captions', 10, 2);
function change_jig_captions($images, $atts)
{
foreach ($images as &$image) {
if (empty($image['extra_class']) || strpos($image['extra_class'], 'jig-contentID-ML-') === false) {
break;
}
if (preg_match('/(\d)+/i', $image['extra_class'], $regs)) {
$id = $regs[0];
} else {
break;
}
$tags = get_the_terms($id, 'post_tag');
if (!empty($tags)) {
$bare_tags = [];
foreach ($tags as $tag) {
$bare_tags[] = $tag->name;
}
$image['title'] = esc_attr(implode(', ', $bare_tags));
}
}
return $images;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment