Home>Support>username from login in contact form

username from login in contact form

We use WordPress for an internal intranet with login for each user.
Is it possible to show and post the username in the contact form.
If possible, this field should be readonly

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 6 days, 12 hours ago Alex S Hi, I Work Here


    Thanks for getting in touch. We don’t directly have a field that allows for this at this time. We can assist you with doing this over premium support by coming up with a snippet that allows for this. If that’s something you would be interested in, check SiteOrigin Premium.

    Alternatively, you can include the submitter’s username as a mail header – which can be viewed by viewing the email source. That can be done by adding the following PHP to your website:

    function add_username_to_email_headers( $headers, $form_data, $instance ) {
    	if ( is_user_logged_in() ) {
    		$current_user = wp_get_current_user(); // Get the current user object
    		$username = $current_user->user_login; // Get the username from the user object
    		// Add the username to the email headers
    		$headers .= 'X-Username: ' . $username . "\r\n";
    return $headers;
    add_filter( 'siteorigin_widgets_contact_form_email_headers', 'add_username_to_email_headers', 10, 3 );

    If you need a method of adding PHP, you can use the Code Snippets plugin.

    Kind regards,

Please log in to post on our forums. Signing up is free.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More