I was able to solve the issue on https://wordpress.stackexchange.com/users/4771/milo suggestion. For this, I created a drop down menu in theme customizer from where I can select a dummy static page to act as Portfolio Page. I’ve used following code for drop down menu:
add_action( 'customize_register', 'th_customize_register' );
function th_customize_register($wp_customize) {
// Add: Drop Down Pages
$wp_customize->add_setting( 'th_portfolio_page_id', array (
'sanitize_callback' => 'absint',
) );
$wp_customize->add_control('th_portfolio_page_id', array(
'label' => esc_html__('Portfolio Page', 'themeshash'),
'description' => esc_html__( 'You must have to define it if you want to set your portfolio as your homepage.', 'themeshash' ),
'section' => 'title_tagline',
'type' => 'dropdown-pages',
) );
}
Once this drop down is setup, now we can add the following code to conditionally assign above defined static page to archive-{post-type}.php
if ( get_option('page_on_front') == get_theme_mod('th_portfolio_page_id') ) {
add_action("pre_get_posts", "th_assign_portfolio_page");
function th_assign_portfolio_page($wp_query){
//Ensure this filter isn't applied to the admin area
if(is_admin()) {
return;
}
if($wp_query->get('page_id') == get_option('page_on_front')):
$wp_query->set('post_type', 'post-type-name-here');
$wp_query->set('page_id', ''); //Empty
//Set properties that describe the page to reflect that
//we aren't really displaying a static page
$wp_query->is_page = 0;
$wp_query->is_singular = 0;
$wp_query->is_post_type_archive = 1;
$wp_query->is_archive = 1;
endif;
}
}
Using this method, now one can choose any dummy static page to act as our post type archive page only once and then we can set/unset that static page as front page just like any other page.