Title: Programmatically add images to category
Last modified: December 3, 2018

---

# Programmatically add images to category

 *  [chriscar111](https://wordpress.org/support/users/chriscar111/)
 * (@chriscar111)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/programmatically-add-images-to-category/)
 * Hi,
 * how can I add images to an existing media category in functions.php ?
 * Thanks!
    -  This topic was modified 7 years, 5 months ago by [chriscar111](https://wordpress.org/support/users/chriscar111/).

Viewing 1 replies (of 1 total)

 *  [supernova42](https://wordpress.org/support/users/supernova42/)
 * (@supernova42)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/programmatically-add-images-to-category/#post-11379271)
 * I’m working on this too
 * I’ve written the code to create media categories which could be based on users
   name as it would need to be unique.
 * This is what I’m playing around with so far.
 * For some reason I cannot get the parent to work as I can’t find what variable
   was used.
 * I now need to assign my uploaded images to specific categories. I could put a
   routine inside so that it runs at log in to create the users category and assign
   all their images to that category.
 * Has anyone else got anywhere with this?
 * Let me know….
 * function insert_category($category,$description,$parent) {
    wp_insert_term( $
   category, ‘media_category’, array( ‘description’ => $description, ‘parent’ =>
   $parent, ‘slug’ => $category //convert to lower case with hyphen ) ); } add_action(‘
   after_setup_theme’,’insert_category’);
 * $first_name =’John’;
    $last_name =’Thomas’; $user_id =’1021′; $username =’thom_j’;
   $parent_name =’Members Boats’; $usercode = $first_name.’ ‘.$last_name.’ [‘.$user_id.’]’;
   insert_category($username,$usercode,$parent_name);

Viewing 1 replies (of 1 total)

The topic ‘Programmatically add images to category’ is closed to new replies.

 * ![](https://ps.w.org/enhanced-media-library/assets/icon-256x256.png?rev=980107)
 * [Enhanced Media Library](https://wordpress.org/plugins/enhanced-media-library/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/enhanced-media-library/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/enhanced-media-library/)
 * [Active Topics](https://wordpress.org/support/plugin/enhanced-media-library/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/enhanced-media-library/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/enhanced-media-library/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [supernova42](https://wordpress.org/support/users/supernova42/)
 * Last activity: [7 years, 1 month ago](https://wordpress.org/support/topic/programmatically-add-images-to-category/#post-11379271)
 * Status: not resolved