You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改WordPress的current-user-link短代码以显示用户邮箱而非ID?

Got it, let's work through this. The default current-user-link shortcode from Profile Builder outputs the user's ID, but we can tweak it to display their email instead—plus hook it up to your Typeform with the email passed as a parameter. Here's how to do it step by step:

1. Use Profile Builder's Filter Hook

Profile Builder includes the wppb_current_user_link_output filter, which lets us override the shortcode's default output. We'll use this to swap the ID with the user's email and adjust the link to point directly to your Typeform.

2. Add the Custom Code

Add this code to your theme's functions.php file, or (even better) a custom functionality plugin (so your changes don't get wiped when you update your theme):

add_filter( 'wppb_current_user_link_output', 'pb_swap_user_id_with_email_for_typeform', 10, 3 );
function pb_swap_user_id_with_email_for_typeform( $original_output, $user_id, $link_attrs ) {
    // Fetch the user object using their ID
    $current_user = get_user_by( 'id', $user_id );
    if ( ! $current_user ) {
        return $original_output; // Fallback if user isn't found
    }

    // Get the user's email address
    $user_email = $current_user->user_email;

    // Replace this with your actual Typeform URL, adding the email as a query parameter
    $typeform_url = 'https://your-typeform-url.com?email=' . urlencode( $user_email );

    // Build the new link: uses your Typeform URL, keeps original link attributes, shows email as text
    $new_link = '<a href="' . esc_url( $typeform_url ) . '" ' . $link_attrs . '>' . esc_html( $user_email ) . '</a>';

    return $new_link;
}

3. Customize to Your Needs

  • Update the Typeform URL: Replace https://your-typeform-url.com with your real Typeform link. The ?email= parameter will pass the user's email to Typeform—you can set up your Typeform to use this parameter to pre-fill the email field automatically.
  • If you just want to show email instead of ID (keep original profile link): If you don't need to link to Typeform and just want the shortcode to point to the user's profile but display their email, replace the $typeform_url line with:
    $profile_url = get_author_posts_url( $user_id ); // Or use your custom profile page URL
    
  • Sanitization: We use esc_url() and esc_html() to keep the output safe and avoid security issues—don't skip these!

4. Test It

Add the original [current-user-link] shortcode to any post or page, and it should now display the logged-in user's email as a link to your Typeform, with their email passed as a parameter.

内容的提问来源于stack exchange,提问作者jose ortiz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:23:36