Give attachments an archive page

This is untested, so apologies there, but I’m thinking out loud, have you tried re-registering the post type afterwards? Or flushed rewrite rules after your initial attempt with flush_rewrite_rules();?

function change_attachment_post_type() {

    $args = get_post_type_object('attachment');
    $args->has_archive = true;
    $args->rewrite = [
        'slug' => 'media'
    ];
    register_post_type($args->name, $args);

    // As a temporary one time, remove after first flush
    flush_rewrite_rules();
}
add_action('init', 'change_attachment_post_type', 20);

Leave a Comment