Last active
January 1, 2022 17:50
-
-
Save Firsh/ce106636ef9a54ceb9ca73559aa5e477 to your computer and use it in GitHub Desktop.
JIG show (custom) taxonomy terms as image title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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