I’ve just tested your code in a function hooked on wp_body_open
and it works:
add_action( 'wp_body_open', 'function_test' );
function function_test() {
$tittle="My new page";
$newPage = array(
'post_type' => 'page',
'post_title' => $tittle,
'post_status' => 'publish'
);
$post_id = wp_insert_post( $newPage);
print_r($post_id);
}
Where do you use this code ?