How to add a featured image to a category taxonomy in WordPress?

How to add a featured image to a category taxonomy in WordPress?

You can add a featured image to a Category Taxonomy in WordPress by using ACF and selecting the categories taxonomy, so now a new image field appears in the category back end page, the same process can be applied to other taxonomy templates such as custom taxonomies.

How to display image on Taxonomy with advanced custom fields ( ACF )?

Today, I needed to display an Advanced Custom Fields (ACF) image on a custom taxonomy page. Here’s the solution: Finally, copy-and-paste code to your functions.php:

How to add image upload field to categories?

If you wanted to add this field to a different taxonomy, e.g. for a custom post type, you’d need to replace the reference to category with a reference to your own taxonomy slug. For example, if you add created a genre taxonomy you would hook this function via add_action ( ‘taxonomy_add_form_fields’, array ( $this, ‘add_category_image’ ), 10, 2 ).

How to create a tribe event calendar taxonomy?

So in the above the Modern Tribe Event Calendar taxonomy is used tribe_events_cat and defined in the initial get_terms array, it is further used in the $image variable just changing the taxonomy name.

How to add an image to a taxonomy?

The ACF image field is set to the custom field name and category_ID. The post is checked if it appears in each category iteration, and if so outputs the image. If you were using a custom taxonomy you can use the has_term function to check if the taxonomy is used by the post in the loop.

How to add an image to a category?

Assign the field to the relevant taxonomy, category in this case, you can also see other Taxonomies present. Now you can upload an image directly on the category page. Now you need to edit the template for outputting the image, this can be either very specific to the category, like category- {id}.php or more generic like archive.php