Monday, 27 November 2017

Adding image upload field to categories and custom taxonomies


This is an updated version of the original post. It started out as a tutorial demonstrating how to add an image to a category but I’ve since amended it to include adding an image to a custom taxonomy as well. How to add an image field to the category field
Here’s what we’re aiming to achieve for standard categories. Details on doing the same for custom taxonomies are below.
There are a lot of tutorials around for how to add fields to categories. However, these mostly use an old method where data is saved to the theme options. But since WordPress 4.4, it’s been possible to save meta data for taxonomies in a similar way to saving post data. Secondly, I wanted the ability to upload an image for the category using the default WordPress media manager. So I came up with the following class:
The whole thing
/**
* Plugin class
**/if ( ! class_exists( ‘CT_TAX_META’ ) ) {class CT_TAX_META {

public function __construct() {
//
}

/*
* Initialize the class and start calling our hooks and filters
* @since 1.0.0
*/
public function init() {
add_action( ‘category_add_form_fields’, array ( $this, ‘add_category_image’ ), 10, 2 );
add_action( ‘created_category’,
Source: https://managewp.org/articles/16701/adding-image-upload-field-to-categories-and-custom-taxonomies




source https://williechiu40.wordpress.com/2017/11/27/adding-image-upload-field-to-categories-and-custom-taxonomies/

No comments:

Post a Comment