There could be many approaches to this. Mine is given below ..
-
First you store the time on which the user was logged in so that you can display the successfull login popup for X number of minutes ..
function store_login_time($user_login, $user) { $userID = $user->ID; update_user_meta( $userID, '_login_time_', time() ); } add_action('wp_login', 'store_login_time', 10, 2);
-
Then you use this code to display the code on the front page of the website for X number of minutes ( 1 minute in my sample ) using
wp_head
action ..function myscript() { $to_time = time(); $from_time = get_user_meta( get_current_user_id(), '_login_time_', true ); $diff = round(abs($to_time - $from_time) / 60,2); // This will run till 1 minute after logging in .. // For Seconds use 0.1 to 0.9 if ( is_front_page() && $diff < "1" ){ ?> <script type="text/javascript"> $( document ).ready(function() { $('<div class="item login">Success! You\'re now signed in.</div>').appendTo('.pop-notice').delay(6000).queue(function() { $(this).remove(); }); }); </script> <?php } } add_action('wp_head', 'myscript');
You can add further options for user roles as per you needs.