WordPress: Replace mailto Links Site-Wide in Minutes

Complete guide to finding and replacing mailto links across your WordPress site.

Why Replace mailto Links in WordPress

Common Problems

mailto Links in WordPress:

  • Expose email to scraping bots
  • Broken on iPhone Mail (iOS 26.1)
  • Poor mobile experience
  • No spam protection
  • No tracking or analytics

Common locations:

  • Theme templates (header, footer)
  • Menu items
  • Widget areas
  • Page/post content
  • Custom HTML blocks
  • Email signatures in author bios

Where mailto Links Hide in WordPress

Theme Locations

1. Header

  • header.php
  • Navigation menus
  • Top bar contact info

2. Footer

  • footer.php
  • Footer widgets
  • Copyright/contact area

3. Sidebar

  • sidebar.php
  • Widget areas
  • Contact widgets

4. Page Templates

  • page.php, single.php
  • Contact page template
  • Custom templates

Content Locations

1. Navigation Menus

  • Appearance → Menus
  • Primary menu
  • Footer menu
  • Mobile menu

2. Widgets

  • Appearance → Widgets
  • Text widgets
  • HTML widgets
  • Custom widgets

3. Pages & Posts

  • Contact page
  • About page
  • Blog posts
  • Author bios

4. Custom Fields

  • ACF fields
  • Meta boxes
  • Custom contact fields

Two Replacement Approaches

Approach 1: Manual Replace (Recommended First)

Best for:

  • Small sites (< 50 pages)
  • Want control over each replacement
  • One-time cleanup

Steps below.

Approach 2: Auto-Replace with JavaScript (Recommended for Large Sites)

Best for:

  • Large sites (hundreds of pages)
  • Ongoing protection
  • Set-and-forget solution

See JavaScript snippet below.

Manual Replacement Steps

Step 1: Create Your Form (5 minutes)

  1. Sign up at SupportRetriever
  2. Complete onboarding
  3. Set up your contact form
  4. Get form URL: https://supportretriever.com/form/your-form-id
  5. Keep it handy for replacements

Step 2: Find mailto Links (10 minutes)

Search Database

Using Search & Replace plugin:

  1. Install "Better Search Replace" (free plugin)
  2. Go to Tools → Better Search Replace
  3. Search for: mailto:
  4. Select all tables
  5. Don't replace yet — just search to see what you have
  6. Review results

Search Theme Files

  1. Go to Appearance → Theme Editor
  2. Search for mailto: in:
    • header.php
    • footer.php
    • functions.php
    • Template files

Check Menus

  1. Go to Appearance → Menus
  2. Check each menu item
  3. Look for "Custom Links" with mailto URLs

Check Widgets

  1. Go to Appearance → Widgets
  2. Open each widget
  3. Check Text/HTML widgets for mailto links

Check Content

  1. Use Better Search Replace to search post content
  2. Or use WordPress search: mailto: in posts/pages

Step 3: Replace in Menus (5 minutes)

For navigation menu items:

  1. Go to Appearance → Menus
  2. Find menu items with mailto links
  3. Click to expand each item
  4. Replace URL with form URL:
Old: mailto:support@example.com
New: https://supportretriever.com/form/your-form-id?source=menu
  1. Update navigation label if needed:
Old label: support@example.com
New label: Contact Support
  1. Save menu

Step 4: Replace in Widgets (5 minutes)

For widget areas:

  1. Go to Appearance → Widgets
  2. Open each Text/HTML widget
  3. Switch to "Text" tab (not Visual)
  4. Find and replace:
<!-- Old -->
<a href="mailto:contact@example.com">Contact Us</a>

<!-- New -->
<a href="https://supportretriever.com/form/your-form-id?source=widget">Contact Us</a>
  1. Save each widget

Step 5: Replace in Theme Files (10 minutes)

For header.php:

  1. Go to Appearance → Theme Editor
  2. Open header.php
  3. Find mailto links
  4. Replace with form URL:
<!-- Old -->
<a href="mailto:<?php echo get_option('admin_email'); ?>">
  Contact
</a>

<!-- New -->
<a href="https://supportretriever.com/form/your-form-id?source=header">
  Contact
</a>
  1. Save file

For footer.php:

<!-- Old -->
<p>Email: <a href="mailto:info@example.com">info@example.com</a></p>

<!-- New -->
<p><a href="https://supportretriever.com/form/your-form-id?source=footer">Contact Us</a></p>

Note: Consider creating a child theme before editing theme files.

Step 6: Replace in Content (10 minutes)

Using Better Search Replace:

  1. Go to Tools → Better Search Replace
  2. Search for: mailto:support@example.com
  3. Replace with: https://supportretriever.com/form/your-form-id?source=content
  4. Select tables: wp_posts, wp_postmeta
  5. Run as dry run first
  6. Review what will change
  7. If good, run for real (uncheck "dry run")
  8. Run search & replace

Or manually edit pages:

  1. Edit each page/post with mailto links
  2. Switch to "Code editor" (or Text tab)
  3. Find and replace mailto links
  4. Update each page

Step 7: Replace in Custom Fields (if applicable)

If using ACF or custom fields:

  1. Go to Posts/Pages with custom fields
  2. Edit each one
  3. Update email fields with form URL
  4. Save changes

JavaScript Auto-Replace Method

When to Use This

Use JavaScript auto-replace if:

  • You have hundreds of pages
  • mailto links are in various places
  • You want ongoing protection
  • New content may have mailto links
  • You don't want to hunt them all down

Installation

Method 1: Theme Footer (Simplest)

  1. Go to Appearance → Theme Editor
  2. Open footer.php
  3. Add before </body> tag:
<script>
(function() {
  const FORM_URL = 'https://supportretriever.com/form/your-form-id';
  
  document.querySelectorAll('a[href^="mailto:"]').forEach(link => {
    const originalHref = link.getAttribute('href');
    const emailMatch = originalHref.match(/mailto:([^?]+)/);
    
    if (emailMatch) {
      link.setAttribute('href', FORM_URL + '?source=autoconvert');
      link.setAttribute('data-original-email', emailMatch[1]);
    }
  });
})();
</script>
  1. Save file

Method 2: Code Snippets Plugin (Recommended)

  1. Install Code Snippets plugin (free)
  2. Go to Snippets → Add New
  3. Title: "Replace mailto Links"
  4. Paste this code:
add_action('wp_footer', function() {
    ?>
    <script>
    (function() {
      const FORM_URL = 'https://supportretriever.com/form/your-form-id';
      
      document.querySelectorAll('a[href^="mailto:"]').forEach(link => {
        const originalHref = link.getAttribute('href');
        const emailMatch = originalHref.match(/mailto:([^?]+)/);
        
        if (emailMatch) {
          link.setAttribute('href', FORM_URL + '?source=autoconvert');
          link.setAttribute('data-original-email', emailMatch[1]);
        }
      });
    })();
    </script>
    <?php
});
  1. Check "Only run in frontend"
  2. Save and activate snippet

Method 3: functions.php

Only if you're using a child theme:

  1. Open child theme's functions.php
  2. Add this code:
function replace_mailto_links() {
    ?>
    <script>
    (function() {
      const FORM_URL = 'https://supportretriever.com/form/your-form-id';
      
      document.querySelectorAll('a[href^="mailto:"]').forEach(link => {
        const originalHref = link.getAttribute('href');
        const emailMatch = originalHref.match(/mailto:([^?]+)/);
        
        if (emailMatch) {
          link.setAttribute('href', FORM_URL + '?source=autoconvert');
          link.setAttribute('data-original-email', emailMatch[1]);
        }
      });
    })();
    </script>
    <?php
}
add_action('wp_footer', 'replace_mailto_links');
  1. Save file

Test the JavaScript Method

  1. Visit your site
  2. Right-click a former mailto link
  3. Inspect element
  4. Verify href now points to form
  5. Click link to test
  6. Verify form opens

Why "Encoding Plugins" Exist (And When Replacing is Better)

Email Encoding/Obfuscation Plugins

Popular plugins:

  • Email Address Encoder
  • Email Obfuscator
  • Hide My Email

What they do:

  • Encode email addresses using JavaScript
  • Attempt to hide from bots
  • Keep mailto functionality

Example encoding:

// Instead of: support@example.com
// Becomes: &#115;&#117;&#112;&#112;&#111;&#114;&#116;&#64;...

When Encoding is Better

Use encoding plugins if:

  • You MUST display actual email address
  • Users need to copy-paste email
  • You can't use a contact form
  • Your situation requires visible email

When Replacing is Better (Most Cases)

Replace with form if:

  • You want maximum spam protection (99% vs 30%)
  • Mobile experience matters (iOS 26.1 issue)
  • You want conversation management
  • You want analytics
  • You want long-term solution

Replacement advantages over encoding:

Feature Encoding Plugin Form Replacement
Spam protection 30-40% 99%+
Mobile reliability Poor Excellent
iOS 26.1 compatible No Yes
Accessibility Medium Excellent
User experience Medium Better
Long-term effectiveness Degrades Permanent
Conversation management No Yes
Analytics No Yes

Verdict: For most websites, replacing with forms provides better protection and user experience than encoding.

Step-by-Step with Screenshots

Visual Guide

Since we're avoiding screenshots, here's a detailed text walkthrough:

Navigation Path:

Finding mailto in Menu:
WordPress Admin → Appearance → Menus → 
Select menu → Expand menu item → 
Look at URL field → Replace if contains "mailto:"

Finding mailto in Widgets:
WordPress Admin → Appearance → Widgets →
Click widget to expand → Switch to Text tab →
Find mailto: in HTML → Replace with form URL

Finding mailto in Theme:
WordPress Admin → Appearance → Theme Editor →
Select header.php or footer.php →
Search page for "mailto:" → Replace each instance →
Click "Update File"

Using Better Search Replace:
WordPress Admin → Tools → Better Search Replace →
"Search for" field: mailto:youremail@example.com →
"Replace with" field: https://supportretriever.com/form/your-id →
Select tables: wp_posts →
Check "Run as dry run" → Click "Run Search/Replace" →
Review results → Uncheck dry run → Run again for real

Verification Checklist

After Replacement

  • Visit homepage — check footer/header links
  • Check contact page — verify no mailto links
  • Check navigation menus — all items work
  • Check sidebar widgets — form links work
  • View source code — search for "mailto:" (should find none)
  • Test on mobile device — verify links open form
  • Test on iPhone — verify iOS 26.1 fix works
  • Submit test message — verify delivery
  • Check email notification — verify receipt

Testing Commands

Search remaining mailto links:

  1. View page source (Ctrl+U / Cmd+U)
  2. Search for "mailto:" (Ctrl+F / Cmd+F)
  3. Should find: 0 results
  4. If you find any, note location and replace

Test form links:

  1. Click each contact link
  2. Verify form opens
  3. Fill out test submission
  4. Verify email arrives
  5. Repeat on mobile

Troubleshooting

"I still see mailto links"

Possible causes:

  • Cached pages (clear cache)
  • CDN cache (clear CDN)
  • Browser cache (hard refresh: Ctrl+Shift+R)
  • Missed locations (check all sources)

Solutions:

  1. Clear all caches
  2. Use incognito/private browsing
  3. Review all locations again

"JavaScript method isn't working"

Possible causes:

  • JavaScript error
  • Script loading order
  • Conflicting plugins

Debug:

  1. Open browser console (F12)
  2. Look for errors
  3. Verify script is loaded
  4. Check if jQuery conflict

Solutions:

  • Wrap in jQuery(document).ready()
  • Load script in footer (not header)
  • Disable plugins one by one to find conflict

"Form URL is wrong"

Fix:

  1. Go to SupportRetriever dashboard
  2. Navigate to Form Management
  3. Copy correct form URL
  4. Update all instances
  5. Clear cache

WordPress Multisite

Network-Wide Replacement

If you have multisite:

  1. Use Better Search Replace on network database
  2. Or run script on each subsite
  3. Or add JavaScript to network theme

Considerations:

  • Different sites may need different forms
  • Use metadata to track which site: ?site=site1
  • Consider central form or separate forms per site

Related Topics

Ready to simplify your support?
Join thousands using SupportRetriever to manage customer conversations.
Try Free

Explore More

Browse All Articles