0

I am trying to connect usetiful to my WordPress Backend.

I need to tag the users and pass information to Usetiful for further personalization.

After going through various similar Q/A threads, I managed to retrieve and pass the User ID to Usetiful, but having trouble getting the User First Name.

Here is the Code Snippet that I am using (Adding code to the Code Snippets Plugin)

<script>
window.usetifulTags = { userId : <?=get_current_user_id() ?>, firstName : <? $user_info = get_userdata(get_current_user_id());$first_name = $user_info->first_name;return $first_name;?>;};

The get_current_user_id() works well, but unable to get the User First Name/Display Name

1 Answer 1

0

Since this is a text, you need to wrap some quotes around it and you should make sure your PHP is a proper value to be evaluated. If you have more operations to be performed, then it is to be recommended to implement a function and only call the function.

<script>
window.usetifulTags = { userId : <?=get_current_user_id() ?>, firstName : "<? $first_name = get_userdata(get_current_user_id())->first_name ?>"};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.