• I use a child theme and I have succesfully added support for categories in the media library.
    Now I can assign categories to any file in the media library, and I can filter the media library by category.
    But I can’t figure how to add filter by category in the popup window which is displayed when you click on “insert media” in a page or a post.
    I could not find the screen id here.
    Please tell me how to proceed, and notice I don’t want to use a plugin for this.

    Here is my code for what is working right now:

    /*
    add categories to medias
    */
    function kpcms_register_taxonomy_for_medias() {
        register_taxonomy_for_object_type( 'category', 'attachment' );
    }
    add_action( 'init', 'kpcms_register_taxonomy_for_medias' );
    
    /*
    add category filter to media library
    */
    function kpcms_add_image_category_filter() {
        $screen = get_current_screen();
        if ( 'upload' == $screen->id ) {
            $dropdown_options = array( 'show_option_all' => __( 'Toutes les Catégories', 'kpcms' ), 'hide_empty' => false, 'hierarchical' => true, 'orderby' => 'name', );
            wp_dropdown_categories( $dropdown_options );
        }
    }
    add_action( 'restrict_manage_posts', 'kpcms_add_image_category_filter' );

  • The topic ‘add filter by category on insert media modal page’ is closed to new replies.