What Does It Take to Have Unique Header Images for WordPress Categories? - Montana Webmaster

What Does It Take to Have Unique Header Images for WordPress Categories?

What Does It Take to Have Unique Header images for WordPress Categories?
WordPress uses the Featured Image in the category pages.

Out of the box, WordPress had programming to attach a unique image to each post. WordPress uses that image on the Category (archive) pages that are lists of posts, along with the excerpt. See example to the right.

WordPress does not have coding to attach a unique banner image to each Post and Page, but there is a plugin called Unique Headers that will do that task.

But, what if you want to have a unique banner image for each Category?

What Does the Programming Have to Do?
  1. The first question is where to hold the link between a Category and an image. The information that makes Categories is in different tables in the WordPress database than Post or Pages. The images themselves aren’t stored in the database, only text information is stored in the database. So, the only thing the database table holds is a link to the image file.
  2. Second, there has to be a field in the Category form to allow the site owner to attach a specific image from the Media Library to the Category. Otherwise, there is no way to put the information into the database.
  3. Third, programming has to pull the image information from the database along with the rest of the Category information. Category pages have two sets of information. There is information about the Category, which makes the title. And, there is information about each Post in that Category, which is used by The Loop.
How is This Different from what the Unique Headers Plugin Does?
WordPress tables for Posts and Categories. Posts are marked with P, and Categories are marked with C.

The Unique Headers plugin gets data from the tables that hold information about Posts and Pages. Category information is in several tables that are separate from the Posts and Pages tables.

The working functions are similar, but the data is in a different storage place, and Categories are run by different files than Posts and Pages. Categories are run by a file called archive.php. Posts are run by a file called single.php. Pages are run by a file called page.php. If a site has customizations, there may be additional files for each of these functions.

Can We Make Use of Existing functions?

By default, there is no image field for Categories in the WordPress core. That means that some other storage strategy must be used to connect an image to a Category. When the WordPress core doesn’t provide a specific storage location for what you want, it’s generally more efficient to research whether there is a high quality, maintained plugin that has already solved the problem. Plugins often make creative use of the existing WordPress tables.

Finding a Plugin

When searching for a plugin that will affect Categories, your search should also include the word Taxonomy. While that may be an uncomfortable word, it applies to both Categories and Tags.

  1. https://wordpress.org/plugins/wp-custom-taxonomy-image/
  2. https://wordpress.org/plugins/taxonomy-images/

Looking at the pages for these two plugins, the second has been updated more recently ( 1 month v 6 months), so I will use it. The plugin seems to work fine. It adds a Header Image field to the Category field form (Dashboard -> Posts -> Category) that goes to the Media Library.

When you save, the plugin adds a record to the WordPress termmeta table in the database. The record connects the Category (a term) to the image. When the image is added to the Media Library, it gets a number that is then available to plugins like this one.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.