I'm looking to load a single custom post type as my homepage. Not an archive but a single post, ID 10190. Looking to do this without a redirect for SEO reasons. What would be the simplest way to achieve this?
Try this
add_action( 'template_redirect', 'so_48395149' );
function so_48395149() {
global $post;
if( is_front_page() ) {
$post = get_post( 10190 );
}
}
Note: I haven't tested this, but you'll be wanting something along these lines.
WordPress stores the currently viewed post in a global $post
variable. In this case, we want to overwrite that with the specified post [type] only on the front page. We use the template_redirect
hook as it's one of the last hooks available before the HTML is generated.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.