Sometimes things that should be easy are hard…
Today, I needed to display an Advanced Custom Fields (ACF) image on a custom taxonomy page. Here’s the solution:
First, create the image field and apply it to the taxonomy like this:
Make sure you have the image field set to output the “Image Array” like this:
Now, go to your taxonomy term and add an image like this:
Finally, copy-and-paste code to your functions.php:
add_action( 'loop_end', 'output_before_taxonomy_loop' );
function output_before_taxonomy_loop(){
if (is_tax()) {
// Display the artist image
$queried_object = get_queried_object();
$taxonomy = $queried_object--->taxonomy;
$term_id = $queried_object->term_id;
$terms = get_field( 'artist_image', $taxonomy.'_'.$term_id);
if( $terms ) {
echo '<img src="'. $terms['url'] .'">';
} else {
//do nothing
}
}
}
Finally, bask in the glory that is Advanced Custom Fields’ taxonomy image fields!
Ain’t life grand? Well…mostly?
More posts from themightymo.com
How to Whitelist SEM Rush IPs in Cloudflare
Alright, I’m going to show you how to whitelist a set of IPs on CloudFlare. In our case we use SEMrush and we want to make sure the SEMrush has full access to our sites.
How to install a Cloudflare SSL certificate on Siteground
Hey there! In this video, I’ll show you how to install a Cloudflare SSL certificate on your SiteGround website. I’ve noticed that Let’s Encrypt sometimes doesn’t renew properly due to conflicts with Cloudflare, so this is a great solution. We’ll use TCwebsecurity.com as the guinea pig. I’ll walk you through the process step-by-step. Once we…
How to Download a Website from Wayback Machine
Today I ran into an issue where a bunch of website files were deleted off the server, and I was called upon to restore the old files. After first pursuing other options (e.g. backups), I landed on Wayback Machine as the next best choice. Thankfully, there’s a handy command line tool for downloading any site…