On wordpress, using ACF I've added a taxonomy field to the attachment to all images. I now want to display the taxonomy field in the html 'id="the-taxonomy">'. My main goal is using it as an anchor. So you'd go to my website - notreallyruby.com/work/toast#the-taxonomy.
I cannot seem to display the taxonomy tag in the html. At the moment it is just displaying the first random tag.
The html looks like this - https://paste.pics/98d4ab6b52b0951c31df62b54534b1b7 and the attachment looks like this: https://paste.pics/06d35483028b09520dc3d822d10d06e5 At the moment it says id="Apples" I want it to say "business card"
Id appreciate any help. Thank you.
<?php
add_filter('the_content','new_content');
function new_content($content) {
$term = get_queried_object();
$test = get_field('tag_cat_acf', get_post_thumbnail_id());
{
$content = str_replace('<img ', '<img data-attr="'. $test->name .'" ', $content);
return $content;
}
}
?>
$test
would have to be an object with a name property. What field type are you using, and why and how are you applying it? It's also not clear why you're trying to capture a$term
object at all, since it's not used.the_content
filter will likely produce scattershot results if practicable at all. You might want to withdraw this question and create a different, more focused one. However, you might want to make sure that you want to use a a WP Gallery Block for your purposes before tunneling down this particular rabbit hole.