0

This question already has an answer here:

How do I add and display a custom image field to a category?

I know I need to use the hook 'category_add_form_fields' however I am not quite sure how... I am relatively new to wordpress so any help is greatly appreciated!

marked as duplicate by Howdy_McGee, TheDeadMedic, Mark Kaplun, Mayeenul Islam, birgire Dec 2 '15 at 22:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

I have used ACF - Advanced Custom Fields for this multiple times ( http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-taxonomy-term/ ). The problem with taxonomy images & other custom fields is that the values are stored in wp_options table. In bigger sites this will populate the wp_options table a lot and is probably not the most efficient way to store data. You can use advanced techniques to avoid this, but if your site is relatively small, it's okay to use custom fields the way ACF and categories images -plugin (mentioned in answer by lacey tech solutions) do.

-1

I've used this plugin https://wordpress.org/plugins/categories-images a number of times and its great for adding images to categories. Hope this does what you need!

When the plugin is activated on your website and you've added in images for your categories use the following in category.php to output the category images:

<ul>
  <?php foreach (get_categories() as $cat) : ?>
     <li>
        <?php if (function_exists('z_taxonomy_image_url')): ?>
           <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
        <?php else: ?>
           <img src="<?php stylesheet_directory_url(); ?>/images/placeholder.jpg" />
        <?php endif; ?>

       <a href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $cat->cat_name; ?></a>
     </li>
  <?php endforeach; ?>
</ul>

In the example above - if no category image is available you have the option to load in a placeholder image in /wp-content/themes/yourthemename/images/placeholder.jpg

stylesheet_directory_url() will return '/wp-content/themes/yourthemename'

Not the answer you're looking for? Browse other questions tagged or ask your own question.