If you need to save any error OR success message on wordpress function.php file OR any other file then please follow below steps:
Here I explain with one success message save on function file and display on home page:
function.php
<?php
function myTempFun() {
if(!session_id()) {
session_start();
}
$_SESSION['my_session_name'] = 'Write here any message';
}
?>
home page template.php
if ( array_key_exists( 'my_session_name', $_SESSION ) ) {?>
<p><?php echo $_SESSION['my_session_name']; ?></p>
<?php
unset( $_SESSION['my_session_name'] );
}
After session display also unset that , So when you refresh page then second time that session not displaying.
Enjoy!