This tutorial allows you to add a text field to fill the URL of an image for each of your categories.

Add this in your functions.php file:

[sourcecode language="php"]add_action('init', 'my_category_module');[/sourcecode]
[sourcecode language="php"]function my_category_module() {
 add_action ( 'edit_category_form_fields', 'add_image_cat');
 add_action ( 'edited_category', 'save_image');
 }[/sourcecode]

The function to add the extra field :

[sourcecode language="php"]function add_image_cat($tag){
 $category_images = get_option( 'category_images' );
 $category_image = '';
 if ( is_array( $category_images ) && array_key_exists( $tag->term_id, $category_images ) ) {
 $category_image = $category_images[$tag->term_id] ;
 }
 ?>
 <tr>
 <th scope="row" valign="top"><label for="auteur_revue_image">Image</label></th>
 <td>
 <?php
 if ($category_image !=""){
 ?>
 <img src="<?php echo $category_image;?>" alt="" title=""/>
 <?php
 }
 ?>
 <br/>
 <input type="text" name="category_image" id="category_image" value="<?php echo $category_image; ?>"/><br />
 <span>This field allows you to add a picture to illustrate the category. Upload the image from the media tab WordPress and paste its URL here.</span>
 </td>
 </tr>
 <?php
 }[/sourcecode]

Function to save :

[sourcecode language="php"]
function save_image($term_id){
 if ( isset( $_POST['category_image'] ) ) {
 //load existing category featured option
 $category_images = get_option( 'category_images' );
 //set featured post ID to proper category ID in options array
 $category_images[$term_id] =  $_POST['category_image'];
 //save the option array
 update_option( 'category_images', $category_images );
 }
 }
}
[/sourcecode]

To display the image put this in “category.php” or “archive.php” depending on your theme, it’s better to choose “category.php”,  and add this code before the WordPress loop :
:

[sourcecode language="php"]
<?php
 if(is_category()){
 $category_images = get_option( 'category_images' );
 $category_image = '';
 if ( is_array( $category_images ) && array_key_exists( get_query_var('cat'), $category_images ) ){

$category_image = $category_images[get_query_var('cat')] ;
 ?>
 <img src="<?php echo $category_image;?>"/>
 <?php
 }
 }
 ?>
[/sourcecode]

Before applying the changes in this tutorial, make sure your WordPress hosting provider you are using is good enough to offer the right amount of bandwidth that can support the new changes.

You May Also Like

Why WordPress is the ultimate option for Non-techy business owners

In this digital age, every business needs an online presence. This can become an issue for business owners especially who have a limited budget and cannot afford to hire a digital agency or a web developer. Small business owners take up on this task on their own even if they do not possess the required […]

WordPress.com vs. Rocket.net for Bloggers: I Run the Same Stack on Both. Here’s How They Compare.

Choosing a WordPress host in 2026 is not about finding the “best”…

Media Temple is launching a new enterprise WordPress solution

Media Temple, the leading hosting company owned by GoDaddy, launched a new enterprise-grade WordPress hosting solution today and hosting the new-brand service on AWS. The company knowing for its advanced WordPress Hosting service on its own servers that promise a better configuration and supported installs, will keep helping with the security issues and automatically patch […]

5 Common Mistakes Made by WordPress Beginners

  WordPress is a global platform for beginners to start their own website. It is a free platform without any barriers to entry that allows anyone to start a website with just basic knowledge regarding web development. Since it is an extremely easy to use content management system some beginners make very common mistakes when […]