• tibornlp

    (@tibornlp)


    Hello there,

    I should place links on a page that contains a custom user data field.
    For example: mydomain.com/page?VALUE=XXXX
    Where XXXX is a value of a user data field.

    How can I do that?
    Thank you,
    Tibor

Viewing 2 replies - 1 through 2 (of 2 total)
  • You could achieve this using worpdpress shortcode api.
    Create a shortcode which will return the links with the dynamic parameter.
    Then you can use the shortcode where needs to be used.

    Here is an example. creating a shortcode [user_data_link]

    <?php
    // Function to generate link with user data
    function generate_link_with_user_data_shortcode() {
        // Retrieve the current user's data
        $current_user = wp_get_current_user();
        $user_data_value = get_user_meta($current_user->ID, 'your_custom_field_name', true); // Change 'your_custom_field_name' to the actual meta key of your custom field
    
        // Construct the link with the user data value
        $link_url = home_url('/page?VALUE=' . urlencode($user_data_value));
    
        // Return the link HTML
        return '<a href="' . esc_url($link_url) . '">Link with User Data</a>';
    }
    // Register the shortcode
    add_shortcode('user_data_link', 'generate_link_with_user_data_shortcode');
    ?>
    
    Thread Starter tibornlp

    (@tibornlp)

    Hello,
    Thank you so much for your answer and help, I think I can implement this!
    All the best,
    Tibor

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘custom user data field placed in a link’ is closed to new replies.