I want to auto fill some details in contact 7 form , when user is logined and how to pass php value to js.

in function.php

if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
     $current_user = wp_get_current_user();
     * @example Safe usage: $current_user = wp_get_current_user();
     * if ( !($current_user instanceof WP_User) )
     *     return;

     $custemail = $current_user->user_email; 
   $custefname = $current_user->user_firstname; 

} else {


In js

 <script type="text/javascript">
        function codeAddress() {
             alert('ok'); // it is shown on onload 
    var phoneMaddy = '<?php echo $custemail; ?>';
         document.getElementById('nameMaddyC').value=phoneMaddy; // value not changed

        window.onload = codeAddress;

Read more here: how to auto fille conatct form 7 when user is logined


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: