SendGrid click tracking issue
November 28, 2024 · AI Conversations
—
### **1. Disable Click Tracking in SendGrid**
The simplest way to avoid URL modifications by SendGrid is to disable click tracking for emails. To do this:
1. Log in to your SendGrid account.
2. Navigate to **Settings > Tracking > Click Tracking**.
3. Toggle the click tracking feature **Off**.
4. Save the changes.
Disabling click tracking ensures that URLs are not rewritten, preserving their original structure.
—
### **2. Use `rel="noopener noreferrer"` in Links**
SendGrid respects links with specific attributes and does not rewrite them for click tracking. If you're generating the password reset email template programmatically in WordPress (e.g., using `wp_mail()` or a custom email hook), append `rel="noopener noreferrer"` to the link HTML.
Example:
<a href="<?php echo esc_url($reset_url); ?>" rel="noopener noreferrer">Reset Your Password</a>
This informs SendGrid not to modify the link for tracking purposes.
—
### **3. Set Up Domain Authentication (Recommended)**
SendGrid might rewrite URLs due to tracking policies when your domain is not authenticated. Authenticating your domain ensures that SendGrid recognizes your domain as a trusted sender:
1. Log in to SendGrid.
2. Go to **Settings > Sender Authentication**.
3. Set up **Domain Authentication** by following the instructions to add DNS records to your domain.
4. Once authenticated, your emails are less likely to face interference like link rewriting.
—
### **4. Modify the Password Reset Email**
Customize the password reset email to use plain text for the link instead of HTML, which prevents SendGrid from wrapping it:
– Use the `retrieve_password_message` filter to override the email content.
Example:
add_filter('retrieve_password_message', function($message, $key, $user_login) {
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login');
return "You requested a password reset. Click the link below to reset your password:nn" . esc_url($reset_url);
}, 10, 3);
—
### **5. Contact SendGrid Support**
If you need click tracking enabled for other links but want to exclude specific links like the password reset URL:
1. Reach out to SendGrid support.
2. Request help with whitelisting or excluding specific URLs from click tracking.
—
### **6. Alternative Email-Sending Services**
If the problem persists and you cannot disable click tracking, consider switching to an alternative service like **Postmark** or **Amazon SES**, which offer more control over email delivery and URL handling.
Let me know if you need detailed steps for implementing any of these solutions!
—
### **1. Use a Custom Domain for Click Tracking**
SendGrid rewrites URLs with a tracking domain. By default, this domain is not your own (e.g., something like `u12345.ct.sendgrid.net`). Setting up a custom tracking domain ensures the rewritten URLs look cleaner and more trustworthy, while maintaining functionality.
**Steps:**
1. Log in to your SendGrid account.
2. Go to **Settings > Tracking > Click Tracking**.
3. Add a custom tracking domain by following SendGrid's instructions:
– You'll need to add specific DNS records to your domain host.
4. Once configured, the tracking domain will use your custom subdomain, e.g., `click.yourdomain.com`, and URLs will work seamlessly.
—
### **2. Encode the Reset URL Properly**
SendGrid click tracking may break URLs with certain query parameters or special characters. To prevent this:
1. Ensure the password reset URL is properly encoded before sending.
2. Use `rawurlencode()` in your WordPress code.
Example:
add_filter('retrieve_password_message', function($message, $key, $user_login) {
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login');
$reset_link = esc_url($reset_url);
$message = "You requested a password reset. Click the link below to reset your password:nn$reset_link";
return $message;
}, 10, 3);
This ensures that special characters in the URL are preserved and not broken by SendGrid’s tracking rewrite.
—
### **3. Use the `x-sg-escape-clicks` Header**
SendGrid provides a special header (`x-sg-escape-clicks`) to exclude specific links from being tracked.
**Steps:**
1. Add a custom header in your email-sending code.
2. Use `wp_mail()` to include the header in the email.
Example:
add_filter('wp_mail', function($args) {
$args['headers'][] = 'x-sg-escape-clicks: 1';
return $args;
});
This tells SendGrid not to rewrite any links in the email.
—
### **4. Avoid Link Wrapping Issues**
SendGrid tracking sometimes breaks links due to line breaks in the email. Ensure the reset URL is not
Here’s how to implement it:
—
### **Solution: Add SendGrid Escape for the Password Reset Link**
SendGrid allows you to escape individual links from being tracked by surrounding them with “ comments in your email content. Use this technique for the password reset link.
#### **Steps:**
1. Modify the email message for the password reset link using the `retrieve_password_message` filter in WordPress.
2. Wrap the reset link with the “ tags to escape tracking.
Example Code:
add_filter('retrieve_password_message', function($message, $key, $user_login) {
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login');
$escaped_reset_link = '<!--sgq-->' . esc_url($reset_url) . '<!--/sgq-->';
// Customize the email content
$message = "You requested a password reset for your account. Click the link below to reset your password:nn";
$message .= $escaped_reset_link;
return $message;
}, 10, 3);
—
### **What This Does:**
1. The “ tags tell SendGrid to **exclude** the wrapped link from click tracking.
2. Other links in the email will still be tracked as usual.
—
### **Test Your Implementation**
After making the changes:
1. Send a test password reset email.
2. Verify that the password reset link is functional and not rewritten by SendGrid.
3. Confirm that other links in your emails are still tracked.
Let me know if you need further assistance!
// Generate the correct reset password URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Force HTTPS
// Replace the default URL in the email with the forced HTTPS URL
$message = preg_replace('/http://[^s]+/', $reset_url, $message);
return $message;
}, 10, 4);
adjust sqq in above code
### Updated Code with “
add_filter('retrieve_password_message', function ($message, $key, $user_login, $user_data) {
// Generate the correct reset password URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Force HTTPS
// Wrap the reset URL with SendGrid escape tags to prevent click tracking
$escaped_reset_url = '<!--sgq-->' . esc_url($reset_url) . '<!--/sgq-->';
// Replace the default URL in the email with the escaped URL
$message = preg_replace('/http://[^s]+/', $escaped_reset_url, $message);
return $message;
}, 10, 4);
### Key Changes:
1. **SendGrid Escape Tags**: The reset URL is wrapped with “ to exclude it from click tracking.
2. **Escaped URL Replacement**: The `preg_replace` function replaces any existing URL in the email message with the escaped reset URL.
### How It Works:
– **Click Tracking Bypass**: The “ comments prevent SendGrid from rewriting this specific URL for click tracking.
– **HTTPS Enforcement**: The reset URL is forced to use HTTPS using the `set_url_scheme()` function.
– **Email Message Update**: The `preg_replace` ensures that the email message contains the updated and escaped reset URL.
### Testing:
1. Send a test password reset email.
2. Verify that the reset URL is functional and not rewritten by SendGrid.
3. Check that other links in the email, if any, are still tracked correctly.
Let me know if you encounter issues!
—
### Updated Code to Escape Only the Password Reset URL
Here’s how to modify the code to address the issue without relying on “:
add_filter('retrieve_password_message', function ($message, $key, $user_login, $user_data) {
// Generate the correct reset password URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Force HTTPS
// Modify the email message to include the plain reset link
$message = sprintf(
"You requested a password reset for your account on %s.nnTo reset your password, click the following link:nn%snnIf you did not request this, please ignore this email.",
get_bloginfo('name'),
esc_url($reset_url) // Include the URL directly in plaintext
);
return $message;
}, 10, 4);
—
### Explanation:
1. **Plaintext URL**: By embedding the password reset URL directly as plaintext (instead of as an anchor tag), SendGrid is less likely to rewrite the URL for click tracking.
2. **Escaping the URL**: The `esc_url()` function ensures the reset URL is properly formatted and safe.
3. **Custom Message**: The email is rewritten to include the reset URL directly in a plaintext email body.
—
### Alternative: Custom Tracking Exclusion Using Headers
If you still want HTML formatting in the email, you can manually exclude links from tracking by adjusting SendGrid's settings programmatically. This requires adding a specific header or using SendGrid's API.
#### Using `wp_mail` to Add Headers
You can include a `x-sg-escape-clicks` header to disable tracking globally for the email:
add_filter('wp_mail', function ($args) use ($key, $user_login) {
// Generate the reset URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https');
// Update the message body
$args['message'] = sprintf(
"You requested a password reset for your account.nnClick here to reset your password:nn%snnIf you did not request this, ignore this email.",
esc_url($reset_url)
);
// Add the escape-clicks header
$args['headers'][] = 'x-sg-escape-clicks: 1';
return $args;
});
### Final Testing Steps
1. Send a test email using this modified filter.
2. Verify the password reset URL is delivered intact and functional.
3. Check whether other links are still being tracked properly.
Let me know if additional adjustments are needed!
—
### **Solution: Escape Only the Password Reset Link**
To escape only the password reset link, wrap that specific link in plaintext form or use inline HTML without headers that affect the entire email. Here’s how to adjust the code:
#### **Updated Code**
add_filter('retrieve_password_message', function ($message, $key, $user_login, $user_data) {
// Generate the correct password reset URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Ensure HTTPS
// Construct the email message
$message = sprintf(
"You requested a password reset for your account on %s.nnTo reset your password, click the following link (this link is not tracked):nn%snnIf you did not request this, please ignore this email.nnOther links in this email may be tracked.",
get_bloginfo('name'),
esc_url($reset_url) // Include the reset URL in plaintext to avoid tracking
);
// Optionally add other links that should remain tracked
$message .= "nnCheck out our website: <a href='https://example.com'>Visit our site</a>";
return $message;
}, 10, 4);
—
### **How This Works**
1. **Plaintext Reset Link**: The password reset link is presented in plaintext form, which SendGrid will not rewrite for tracking.
2. **Other Links Tracked**: Any other HTML links (e.g., “ tags) in the email will still be tracked by SendGrid's click tracking system.
3. **Clean Separation**: Only the reset URL avoids tracking, while all other links remain functional and trackable.
—
### **Why This Works**
– SendGrid primarily tracks HTML “ links. If the reset link is in plaintext (`https://example.com`), it won't be tracked or modified.
– Other links formatted as HTML will continue to use SendGrid's tracking.
—
### **Final Test Steps**
1. Send a test password reset email.
2. Verify:
– The password reset link is not rewritten or tracked by SendGrid.
– Other links in the email (e.g., a website link) are still tracked correctly.
Let me know if this resolves your issue!
// Generate the correct password reset URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Ensure HTTPS
// Construct the email message
$message = sprintf(
"You requested a password reset for your account on %s.nnTo reset your password, click the following link (this link is not tracked):nn%snnIf you did not request this, please ignore this email.nnOther links in this email may be tracked.",
get_bloginfo('name'),
esc_url($reset_url) // Include the reset URL in plaintext to avoid tracking
);
// Optionally add other links that should remain tracked
$message .= "nnCheck out our website: Visit our site";
return $message;
}, 10, 4);
above unable to bypass sendgrid override
—
### **Alternative Solution: Use Custom HTML in the Email**
Instead of relying on plaintext or escaping globally, you can craft the email in a way that forces SendGrid to bypass tracking for the reset link. You can achieve this by programmatically injecting a custom HTML email format.
#### **Updated Code: Use HTML Email with Non-tracked Reset Link**
add_filter('retrieve_password_message', function ($message, $key, $user_login, $user_data) {
// Generate the correct password reset URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Ensure HTTPS
// Construct the HTML email message
$html_message = sprintf(
"You requested a password reset for your account on %s.<br><br>
<strong>To reset your password, click the following link (not tracked):</strong><br>
<a href='%s' rel='noreferrer noopener' target='_blank'>%s</a><br><br>
If you did not request this, please ignore this email.<br><br>
<strong>Other tracked links:</strong><br>
<a href='https://example.com'>Visit our site</a>",
get_bloginfo('name'),
esc_url($reset_url),
esc_html($reset_url) // Show the full URL for transparency
);
// Apply headers to ensure the email is sent as HTML
add_filter('wp_mail_content_type', function() {
return 'text/html';
});
return $html_message;
}, 10, 4);
—
### **What This Does:**
1. **HTML Format**: The email is sent as HTML, allowing you to use advanced link attributes.
2. **Non-tracked Link**: The password reset link uses:
– `rel="noreferrer noopener"`: Some email clients and SendGrid respect these attributes to prevent rewriting.
– `target="_blank"`: Opens the link in a new tab (optional but recommended).
3. **Tracked Links Remain**: The `Visit our site` link is still an HTML “ tag, so it will be rewritten and tracked by SendGrid.
—
### **Alternative: Inline URL Encoding**
If the above still doesn't work, encode the password reset URL into a button or plain text within the email content.
#### Example:
$html_message = sprintf(
"Click the button below to reset your password (not tracked):<br><br>
<button style='background-color: #0073aa; color: #fff; padding: 10px; border: none; border-radius: 5px;'>
<a href='%s' style='color: #fff; text-decoration: none;' rel='noreferrer noopener' target='_blank'>Reset Password</a>
</button><br><br>
If you did not request this, ignore this email.<br><br>
Other links remain tracked:<br>
<a href='https://example.com'>Visit our site</a>",
esc_url($reset_url)
);
—
### **Test the Changes**
1. Send a test password reset email.
2. Verify the following:
– The password reset link opens correctly without being rewritten.
– Other links in the email are still tracked as expected.
If SendGrid is still rewriting the password reset link, you may need to **contact SendGrid support** to exclude specific URLs from tracking while keeping click tracking enabled for others.
### Approach to Override the Password Reset Link
1. **Change the Link Format**: Instead of using a standard hyperlink format, you can present the link in plaintext while still ensuring it remains clickable.
2. **Use a Custom Link Format**: Some users have found success by using a different structure that might not trigger SendGrid's rewrite.
Here’s how you can adjust the code:
### **Code Implementation**
add_filter('retrieve_password_message', function ($message, $key, $user_login, $user_data) {
// Generate the correct password reset URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Ensure HTTPS
// Construct the email message with the reset URL in a format that is less likely to be altered
$message = sprintf(
"You requested a password reset for your account on %s.nn" .
"To reset your password, please copy and paste the following link into your browser:nn" .
"%snn" .
"If you did not request this, please ignore this email.nn" .
"Other links in this email may be tracked.",
get_bloginfo('name'),
esc_url($reset_url) // Present the reset URL directly
);
// Optionally add other tracked links if needed
$message .= "nnCheck out our website: <a href='https://example.com'>Visit our site</a>";
return $message;
}, 10, 4);
### Explanation of the Changes:
1. **Plaintext Link Instructions**: Instead of providing a clickable link, the code instructs the user to copy and paste the link into their browser. This helps to avoid SendGrid's click tracking altogether since it’s presented as plain text.
2. **Escaped URL**: The reset URL is still escaped properly to ensure it is valid when used.
3. **Maintained HTML for Other Links**: You can still include other tracked links in HTML format in the same message.
### Testing the Implementation:
1. **Send a Test Email**: Trigger the password reset to see how the email looks.
2. **Check the Password Reset Link**: Ensure the link is delivered correctly and can be copied and pasted.
3. **Verify Other Links**: Check that any additional links you have in the email retain tracking functionality.
### Alternative: Using a Button with Non-tracked Attributes
If you want to keep the link clickable without SendGrid rewriting it, try formatting the password reset link using a button styled in HTML, but with attributes to limit SendGrid's interference:
$message = sprintf(
"You requested a password reset for your account on %s.<br><br>" .
"<strong>To reset your password, click the button below:</strong><br><br>" .
"<a href='%s' style='background-color: #0073aa; color: #ffffff; padding: 10px; border-radius: 5px; text-decoration: none;'>Reset Password</a><br><br>" .
"If you did not request this, please ignore this email.<br><br>" .
"<strong>Other links may be tracked:</strong><br>" .
"<a href='https://example.com'>Visit our site</a>",
get_bloginfo('name'),
esc_url($reset_url)
);
### Final Consideration:
If SendGrid continues to rewrite your password reset links, consider contacting their support team for assistance in excluding specific URLs from click tracking. They may provide specific settings or configurations that allow you to manage link tracking more effectively.
// Generate the correct reset password URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Force HTTPS
// Wrap the reset URL with SendGrid escape tags to prevent click tracking
$escaped_reset_url = '' . esc_url($reset_url) . '';
// Replace the default URL in the email with the escaped URL
$message = preg_replace('/http://[^s]+/', $escaped_reset_url, $message);
return $message;
}, 10, 4);
add clicktracking=off before href
### Updated Code Implementation
add_filter('retrieve_password_message', function ($message, $key, $user_login, $user_data) {
// Generate the correct reset password URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Force HTTPS
// Wrap the reset URL with SendGrid escape tags to prevent click tracking
$escaped_reset_url = '<!--sgq-->' . esc_url($reset_url) . '?clicktracking=off<!--/sgq-->';
// Replace the default URL in the email with the escaped URL
$message = preg_replace('/http[s]?://[^s]+/', $escaped_reset_url, $message);
return $message;
}, 10, 4);
### Explanation of Changes:
1. **Reset URL Generation**: The code generates the password reset URL and ensures it is secure (using HTTPS).
2. **Escaping with SendGrid Tags**: The `escaped_reset_url` variable wraps the URL in SendGrid's escape tags (“ and “) and appends `?clicktracking=off` to the URL. This additional query parameter helps indicate that tracking should be disabled for that specific link.
3. **Regular Expression Update**: The `preg_replace` function uses a regular expression that captures both `http://` and `https://` URLs, ensuring the reset link is replaced regardless of its protocol.
### Test the Changes:
1. **Send a Test Password Reset Email**: Trigger the password reset process and review the email content.
2. **Check the Reset Link**: Ensure the password reset link is properly formatted with the escape tags and the `clicktracking=off` parameter.
3. **Validate Other Links**: Confirm that other links in the email are still tracked by SendGrid as expected.
### Note:
If you encounter issues with the SendGrid click tracking still altering the password reset link despite these changes, consider reaching out to SendGrid support for specific configurations related to link tracking behavior. They may have additional recommendations or settings to address this functionality directly.
### Updated Code Implementation
add_filter('retrieve_password_message', function ($message, $key, $user_login, $user_data) {
// Generate the correct reset password URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Force HTTPS
// Create the link with the clicktracking parameter set to off
$link_with_no_tracking = sprintf(
'<a href="%s?clicktracking=off" rel="noreferrer noopener" target="_blank">%s</a>',
esc_url($reset_url),
esc_html__('Reset Password', 'your-text-domain') // Change 'your-text-domain' to your theme or plugin's text domain
);
// Replace the existing URL in the email with the new link
$message = preg_replace('/http[s]?://[^s]+/', $link_with_no_tracking, $message);
return $message;
}, 10, 4);
### Explanation of Changes:
1. **Reset URL Generation**: The password reset URL is generated securely using HTTPS.
2. **Creating the “ Tag**: The link is created with the `href` set to the reset URL appended with `?clicktracking=off`. This indicates to SendGrid that tracking should not be applied to this specific link.
– The `rel="noreferrer noopener"` attributes are added for security reasons when opening the link in a new tab.
– The link text is dynamically generated and can be translated using `esc_html__`.
3. **Replacing the Link**: The existing URL in the message is replaced with the newly created link containing the `clicktracking=off` parameter.
### Test the Changes:
1. **Send a Test Password Reset Email**: Trigger a password reset email and verify its content.
2. **Check the Password Reset Link**: Confirm that the link appears correctly formatted and includes the `clicktracking=off` parameter.
3. **Validation**: Ensure that any other links in the email continue to be tracked by SendGrid.
### Final Note:
If you continue to have issues with SendGrid altering the password reset link despite the `clicktracking=off` parameter, consider reaching out to SendGrid support for further assistance regarding link tracking behavior and how to manage it effectively for specific URLs.
text
### Updated Code Implementation
add_filter('retrieve_password_message', function ($message, $key, $user_login, $user_data) {
// Generate the correct reset password URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Force HTTPS
// Create the link with the clicktracking parameter set to off
$link_with_no_tracking = sprintf(
'<a clicktracking="off" href="%s">%s</a>',
esc_url($reset_url),
esc_html__('Reset Password', 'your-text-domain') // Change 'your-text-domain' to your theme or plugin's text domain
);
// Replace the existing URL in the email with the new link
$message = preg_replace('/http[s]?://[^s]+/', $link_with_no_tracking, $message);
return $message;
}, 10, 4);
### Explanation of Changes:
1. **Reset URL Generation**: The reset password URL is generated and forced to use HTTPS for security.
2. **Creating the “ Tag**:
– The “ tag includes the `clicktracking="off"` attribute, which should signal SendGrid not to apply click tracking to this specific link.
– The `href` is set to the reset URL, and the link text is dynamically generated.
3. **Replacing the Link**: The existing URL in the message is replaced with this newly constructed link.
### Test the Changes:
1. **Send a Test Password Reset Email**: Trigger the password reset process to check the email output.
2. **Check the Link Format**: Verify that the “ tag appears correctly in the email with the `clicktracking="off"` attribute.
3. **Functionality**: Ensure that clicking the link takes the user to the reset password page as expected without tracking interference.
### Important Note:
– Ensure your WordPress theme or plugin's text domain is correctly set in `esc_html__('Reset Password', 'your-text-domain')` to support translation.
– If you continue to face issues with SendGrid's click tracking behavior, you may need to reach out to their support for further assistance on managing link tracking.
### Alternative Approach
1. **Using a Plain Text Link**: Present the link as plain text, instructing the user to copy and paste it into their browser. This method avoids any tracking issues entirely.
2. **Modify Link Format**: Sometimes, using an unconventional format for the link can prevent SendGrid from altering it.
### Updated Code Implementation
Here’s a revised version that explicitly creates the link without using standard hyperlink formatting, which might help to avoid any tracking modifications:
add_filter('retrieve_password_message', function ($message, $key, $user_login, $user_data) {
// Generate the correct reset password URL
$reset_url = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login));
$reset_url = set_url_scheme($reset_url, 'https'); // Force HTTPS
// Construct the password reset link without standard hyperlink formatting
$link_with_no_tracking = sprintf(
'<a href="%s" onclick="return false;">Reset Password (copy this link: %s)</a>',
esc_url($reset_url),
esc_url($reset_url)
);
// Replace the existing URL in the email with the new link
$message = preg_replace('/http[s]?://[^s]+/', $link_with_no_tracking, $message);
return $message;
}, 10, 4);
### Explanation of the Code:
1. **Reset URL Generation**: The reset URL is generated as before, ensuring it uses HTTPS.
2. **Link Formatting**:
– The “ tag uses `onclick="return false;"` to prevent any default click action, making the link effectively act as plain text but still remain clickable.
– The reset URL is displayed as part of the text instructing users to copy it.
3. **Replacing the Existing URL**: The `preg_replace` function replaces the existing URL in the message with the newly constructed link.
### Testing the Implementation:
1. **Send a Test Password Reset Email**: Initiate the password reset process and verify the email output.
2. **Review the Link**: Check that the link displays correctly and instructs users to copy the URL.
3. **Functionality**: Ensure that users can successfully reset their passwords using the provided link.
### Additional Notes:
– If this method still does not work as expected, consider contacting SendGrid support to discuss how they handle click tracking for specific links and if there are any recommended practices for preventing tracking on password reset links.
– As a final alternative, you could also try sending the link in plain text without a hyperlink at all, but this may reduce usability since users will have to copy and paste the URL manually.
### Example of Plain Text Link:
If necessary, you can also resort to completely plain text, as shown below:
$message = sprintf(
"You requested a password reset for your account on %s.nn" .
"To reset your password, copy and paste the following link into your browser:nn" .
"%snn" .
"If you did not request this, please ignore this email.",
get_bloginfo('name'),
esc_url($reset_url)
);
This format should definitely bypass any tracking but requires users to copy and paste the URL manually.