How to Display Image on Taxonomy with Advanced Custom Fields (ACF)

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:
acf image field on

Make sure you have the image field set to output the “Image Array” like this:
acf array

Now, go to your taxonomy term and add an image like this:
acf add image to

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!

acf taxonomy image display
Artist is https://cryns.com

Ain’t life grand? Well…mostly?

Posted in

Toby Cryns

RSS From Toby’s Blog

  • Fortify Your WordPress Site: Essential Security Steps
    Securing your WordPress site is a critical component of maintaining your online presence and safeguarding your data. Security is no longer a luxury, it has become a necessity in today’s digital world, where threats are lurking at every corner. This piece dives deep into WordPress security basics, giving you a comprehensive understanding of common vulnerabilities…
  • Master Your Site: Customizing WordPress Themes
    Just as a house is more than bricks and mortar, a WordPress site is much more than simple code. It’s a cohesive structure built with various layers such as PHP, HTML, CSS, and other key elements. Customizing WordPress themes involves gaining an in-depth understanding of this structure, learning to inspect and adjust design elements with…
  • Mastering WordPress Basics for Beginners within Hours
    Welcome to the world of WordPress, a widely used Content Management System (CMS) that powers millions of websites worldwide. Being immensely flexible and user-friendly, WordPress offers an endless scope to create, manage, and customize your website according to your needs and preferences. In this segment, we attempt to introduce you to the basics of WordPress,…

More posts from themightymo.com

google business reviews disappeared 1

Google Removed Our Business Listing – How we restored our biz to the Map and got our reviews back.

By The Mighty Mo! Design Co. | June 12, 2023

I was about to send an email to a potential customer pointing them to our 5-star Google Reviews via our Google Business profile (e.g. the Google Map), hoping this added information about our customers’ past experiences might help me close a deal. But when I checked the Google Reviews link, it was down. And after…

cloudways off site backup pricing

The Price We Pay: Cloudways Off-Site Backup vs. Budget WordPress Hosts

By The Mighty Mo! Design Co. | June 5, 2023

Cloudways Off-Site Backup Pricing Calculator: The Ultimate Cost Guide

gravity forms email spam blacklist

How to Block Mailinator and other spam from Gravity Forms

By The Mighty Mo! Design Co. | May 30, 2023

I’ve had a couple of scenarios where I’ve needed to block a specific domain from filling out Gravity Forms on my WordPress site. Today I needed to block spammy “mailinator.com” submissions from a contact form. The solution was simple: Install and configure the Gravity Forms Email Blacklist plugin. In a few minutes – all done!

RSS From Toby’s Blog

  • Fortify Your WordPress Site: Essential Security Steps
    Securing your WordPress site is a critical component of maintaining your online presence and safeguarding your data. Security is no longer a luxury, it has become a necessity in today’s digital world, where threats are lurking at every corner. This piece dives deep into WordPress security basics, giving you a comprehensive understanding of common vulnerabilities…
  • Master Your Site: Customizing WordPress Themes
    Just as a house is more than bricks and mortar, a WordPress site is much more than simple code. It’s a cohesive structure built with various layers such as PHP, HTML, CSS, and other key elements. Customizing WordPress themes involves gaining an in-depth understanding of this structure, learning to inspect and adjust design elements with…
  • Mastering WordPress Basics for Beginners within Hours
    Welcome to the world of WordPress, a widely used Content Management System (CMS) that powers millions of websites worldwide. Being immensely flexible and user-friendly, WordPress offers an endless scope to create, manage, and customize your website according to your needs and preferences. In this segment, we attempt to introduce you to the basics of WordPress,…