<?php
/*-----------------------------------------------------------------------------------*/
/* ref: http://wordpress.stackexchange.com/questions/18013/how-do-you-use-a-cpt-as-the-default-home-page */
/*-----------------------------------------------------------------------------------*/
function add_index_page_to_dropdown( $post ){
$args = array(
'post_type' => 'index-page'
);
$items = get_posts($args);
$post = array_merge($post, $items);
return $post;
}
add_filter( 'get_pages', 'add_index_page_to_dropdown' );
function enable_front_page_index_page( $query ){
if('' == $query->query_vars['post_type'] && 0 != $query->query_vars['page_id'])
$query->query_vars['post_type'] = array( 'page', 'index-page' );
}
add_action( 'pre_get_posts', 'enable_front_page_index_page' );
In case anyone would like to include this feature:
1. Copy paste this snippet in your functions.php file.
2. replace method names to suit your needs
3. Make sure you replace the "index-page" value which corresponds to your CPT type.
4. You're done! Visit Settings > Reading in your admin, set "Front page displays" to "A static page (select below)" and open dropdown. Your custom post should be there.
1. Copy paste this snippet in your functions.php file.
2. replace method names to suit your needs
3. Make sure you replace the "index-page" value which corresponds to your CPT type.
4. You're done! Visit Settings > Reading in your admin, set "Front page displays" to "A static page (select below)" and open dropdown. Your custom post should be there.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.