How to include support for all page types, calendar urls, archive, etc

You need to add a check if the view that you are currently on is a single-view page or an archive ( or any other taxonomy page ). If you are on an archive page, the get_queried_object() will not return a Post object, therefore the error

The check you need to add can be the following:

if ( ! is_archive() ) {
    $wp_the_query   = $GLOBALS['wp_the_query'];
    $queried_object = $wp_the_query->get_queried_object();
    $post_object    = sanitize_post( $queried_object );
    $post_type      = $post_object->post_type;
    $post_id        = $post_object->ID;
}