Sunday, September 20, 2026
HomeWordPress Developmentphp - How one can pull the present person's electronic mail and...

php – How one can pull the present person’s electronic mail and insert right into a script placeholder?


You did not present any info on the way you’re getting the script on the web page to start with. Assuming that that is one thing you might have hardcoded into your template, here’s a method you possibly can method it.

First, you might want to examine if the person is logged in, as a result of if they aren’t, there is not any level in outputting something because you would not have any knowledge.

Subsequent, use wp_get_current_user() to get the present person’s data in an ordinary WP person object. The person’s electronic mail handle will likely be in that object as $user->user_email.

This is what that appears like in follow:

<?php
// Is the person logged in?
if ( is_user_logged_in() ) {
     // Get the present person.
     $person = wp_get_current_user();
     // Output your script.
     ?><script>
          rewardful('convert', { electronic mail: '<?php echo $user->user_email; ?>' })
     </script><?php
} ?>

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments