Created
February 13, 2017 14:31
-
-
Save jplhomer/b75a90183f151f7b4a4415b9a16a5455 to your computer and use it in GitHub Desktop.
Show Taghound Tags on the front-end of a WordPress post.
This file contains hidden or 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 | |
// single.php or whatever template you'd like | |
// 1. Get the ID of the current thumbnail for the post | |
$attachment_id = get_post_thumbnail_id(); | |
// 2. Get the tags associated to the image | |
$tags = wp_get_post_terms($attachment_id, 'tmt_tag'); | |
// 3. Collect the names of each tag | |
$tags = array_map(function($tag) { | |
return $tag->name; | |
}, $tags); | |
?> | |
<h1><?php the_title(); ?> | |
<p> | |
Tags for this image: | |
<?php | |
// 4. Print them out where you'd like | |
echo implode(', ', $tags); | |
?> | |
</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment