December 16, 2016

Wordpress temporary session to save any message?



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!

3 comments:

  1. I am so grateful to find your particular post. I have bookmarked this website and I will keep visiting you for further such interesting posts.
    Web Company in India Company | Web development Company Bangalore
    Web Development Company in Bangalore | Responsive Web development

    ReplyDelete
  2. read this blog this is helpful for you to https://www.weblinkindia.net/blog/wordpress-website-complexity-impacts-seo

    ReplyDelete

Integrating Google reCAPTCHA v3 in HTML Form with PHP

  What is Google reCAPTCHA v3? Google reCAPTCHA is a free service that helps protect websites from spam and abuse. reCAPTCHA v3 is the lates...