{"id":20508472,"url":"https://github.com/daggerhart/taxonomy-term-image","last_synced_at":"2025-04-13T22:07:50.029Z","repository":{"id":29396035,"uuid":"32931269","full_name":"daggerhart/taxonomy-term-image","owner":"daggerhart","description":"Example plugin for adding an image upload field to taxonomy terms in WordPress","archived":false,"fork":false,"pushed_at":"2020-02-03T20:46:23.000Z","size":41,"stargazers_count":55,"open_issues_count":0,"forks_count":19,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-13T22:07:36.758Z","etag":null,"topics":["taxonomy","wordpress"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daggerhart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-26T14:12:18.000Z","updated_at":"2024-11-13T10:12:26.000Z","dependencies_parsed_at":"2022-09-06T17:01:09.333Z","dependency_job_id":null,"html_url":"https://github.com/daggerhart/taxonomy-term-image","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daggerhart%2Ftaxonomy-term-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daggerhart%2Ftaxonomy-term-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daggerhart%2Ftaxonomy-term-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daggerhart%2Ftaxonomy-term-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daggerhart","download_url":"https://codeload.github.com/daggerhart/taxonomy-term-image/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788925,"owners_count":21161727,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["taxonomy","wordpress"],"created_at":"2024-11-15T20:18:51.654Z","updated_at":"2025-04-13T22:07:50.007Z","avatar_url":"https://github.com/daggerhart.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Taxonomy Term Image\n\nAn example plugin for adding an image upload field to taxonomy term edit pages, and an example of the new taxonomy term meta data added in WordPress 4.4. This example IS NOT compatible with any version of WordPress lower than 4.4, it is meant to be used as an example only.\n\n### How to use within a theme or plugin:\n\n**Setup file:**\n\n1. Delete plugin meta data at the top of taxonomy-term-image.php\n1. include_once taxonomy-term-image.php\n\n### Hooks\n\n**filter `taxonomy-term-image-taxonomy`**:\n\nChange the taxonomy targeted by the plugin. By default, the `category` taxonomy is the only taxonomy targeted. You can change this to tags if you'd like following the example below:\n\n```php\n\tfunction the_term_image_taxonomy( $taxonomy ) {\n\t\t// use for tags instead of categories\n\t\treturn 'post_tag';\n\t}\n\tadd_filter( 'taxonomy-term-image-taxonomy', 'the_term_image_taxonomy' );\n```\n\nAlternatively, the plugin can target more than one taxonomy by providing it an array of taxonomy slugs:\n\n```php\n\tfunction the_term_image_taxonomy( $taxonomy ) {\n\t\t// use for tags and categories\n\t\treturn array( 'post_tag', 'category' );\n\t}\n\tadd_filter( 'taxonomy-term-image-taxonomy', 'the_term_image_taxonomy' );\n```\n\n**filter `taxonomy-term-image-labels`**:\n\nChange the field and button text.\n\n```php\n\tfunction the_taxonomy_term_image_labels( $labels ) {\n\t\t$labels['fieldTitle'] = __( 'My Super Rad Plugin', 'yourdomain' );\n\t\t$labels['fieldDescription'] = __( 'This plugin is cool, and does neat stuff.', 'yourdomain' );\n\n\t\treturn $labels;\n\t}\n\tadd_filter( 'taxonomy-term-image-labels', 'the_taxonomy_term_image_labels' );\n```\n\n**filter `taxonomy-term-image-meta-key`**:\n\nChange the meta key used to save the image ID in the term meta data\n\n```php\n\tfunction the_taxonomy_term_image_meta_key( $option_name ) {\n\t\t// store in term meta where term meta key is = 'my_term_meta_key'\n\t\treturn 'my_term_meta_key';\n\t}\n\tadd_filter( 'taxonomy-term-image-meta-key', 'the_taxonomy_term_image_meta_key' );\n```\n\n**filter `taxonomy-term-image-js-dir-url`**:\n\nChange where the js file is located. (no trailing slash)\n\n```php\n\tfunction my_taxonomy_term_image_js_dir_url( $option_name ) {\n\t\t// change the js directory to a subdirectory of this hook\n\t\treturn plugin_dir_url( __FILE__ ) . '/js';\n\t}\n\tadd_filter( 'taxonomy-term-image-js-dir-url', 'my_taxonomy_term_image_js_dir_url' );\n```\n\n**show image on archive template**\n\nTerm Image IDs are automatically attached to terms that are passed through the `get_term` and `get_terms` filters as the `-\u003eterm_image` property.\n\n```php\n\t$term = get_term( 123, 'category' );\n\n\tif ( $term-\u003eterm_image ) {\n\t\techo wp_get_attachment_image( $term-\u003eterm_image, 'full' );\n\t}\n```\n\nIn order to retrieve the term image on an archive page:\n\n```php\n\t$term = get_queried_object();\n\n\tif ( $term-\u003eterm_image ) {\n\t    echo wp_get_attachment_image( $term-\u003eterm_image, 'full' );\n    }\n```\n\n### References:\n\n**Articles:**\n\n* [Using Media Uploader in plugins](http://mikejolley.com/2012/12/using-the-new-wordpress-3-5-media-uploader-in-plugins/)\n* [Introduction to WordPress term meta](http://themehybrid.com/weblog/introduction-to-wordpress-term-meta)\n\n**Code References:**\n\n* Plugin Hooks\n    * action [admin_init](http://codex.wordpress.org/Plugin_API/Action_Reference/admin_init)\n    * action [admin_enqueue_scripts](http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts)\n\t* function [wp_register_script](https://developer.wordpress.org/reference/functions/wp_register_script/)\n\t* function [wp_localize_script](https://developer.wordpress.org/reference/functions/wp_localize_script/)\n\t* function [wp_enqueue_script](https://developer.wordpress.org/reference/functions/wp_enqueue_script/)\n* Term Meta Data\n    * function [register_meta](https://developer.wordpress.org/reference/functions/register_meta/)\n    * function [get_term_meta](https://make.wordpress.org/core/2015/10/23/4-4-taxonomy-roundup/)\n    * function [update_term_meta](https://make.wordpress.org/core/2015/10/23/4-4-taxonomy-roundup/)\n    * function [delete_term_meta](https://make.wordpress.org/core/2015/10/23/4-4-taxonomy-roundup/)\n* Taxonomy Hooks\n    * action [create_{$taxonomy}](https://developer.wordpress.org/reference/hooks/create_taxonomy/)\n    * action [edit_{$taxonomy}](https://developer.wordpress.org/reference/hooks/edit_taxonomy/)\n    * action [{$taxonomy}_add_form_fields](https://developer.wordpress.org/reference/hooks/taxonomy_add_form_fields/)\n    * action [{$taxonomy}_edit_form_fields](https://developer.wordpress.org/reference/hooks/taxonomy_edit_form_fields/)\n    * filter [get_term](https://developer.wordpress.org/reference/hooks/get_term/)\n    * filter [get_terms](https://developer.wordpress.org/reference/hooks/get_terms/)\n    * filter [get_object_terms](https://developer.wordpress.org/reference/hooks/get_object_terms/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaggerhart%2Ftaxonomy-term-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaggerhart%2Ftaxonomy-term-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaggerhart%2Ftaxonomy-term-image/lists"}