// 404 to homepage

add_action('wp', function() {
if (!is_admin() && is_404()) {
if ( (defined('DOING_CRON') && DOING_CRON) || (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) ) {
return;
}
if ( (function_exists('is_bbpress') && is_bbpress()) || (function_exists('bp_is_user_profile') && bp_is_user_profile()) ) {
return;
}
wp_redirect(esc_url_raw(home_url()), 301);
die;
}
});