Sparrow Plugins

Guide · 2026-11-23

How to find broken links in WordPress

Links break quietly. A site you linked to years ago moves, a post of your own gets a new slug, or a typo slips into a URL. Nobody tells you. Readers just hit a dead page and leave.

This guide shows how to find broken links on a WordPress site without installing anything, and then how to fix them. At the end there's a shorter route with a plugin, if you'd rather not run scripts.

What counts as a broken link

A link is broken when the address it points to doesn't return a working page. The common cases are:

Links between your own posts break too, usually after a slug change or a deleted page. Those are the ones you can fix fastest, so start there.

Method 1: Google Search Console

If your site is verified in Google Search Console, open the Page indexing report and look at the reason Not found (404). Click it to see example URLs, then use the inspect icon next to one to see where Google found it.

Google's own help page says a 404 isn't always a problem. A page you removed on purpose with no replacement can stay a 404. Fix the ones you link to yourself or list in your sitemap. If the page moved, point the old address at the new one with a 301 redirect.

The limit here is that Search Console only shows your own URLs. It won't tell you that a link inside your post to someone else's site has died.

Method 2: check outgoing links with WP-CLI

If your host gives you SSH and WP-CLI, you can check every link in your published posts with a short script. It uses functions that ship with WordPress: wp_extract_urls() pulls URLs out of the content, and wp_remote_get() requests each one.

Save this as check-links.php somewhere outside your web root:

<?php
// Run with: wp eval-file check-links.php
$mysite_ids = get_posts(
    array(
        'post_type'      => array( 'post', 'page' ),
        'post_status'    => 'publish',
        'posts_per_page' => -1,
        'fields'         => 'ids',
    )
);

$mysite_seen = array();

foreach ( $mysite_ids as $mysite_id ) {
    $mysite_urls = wp_extract_urls( get_post_field( 'post_content', $mysite_id ) );

    foreach ( $mysite_urls as $mysite_url ) {
        if ( 0 !== strpos( $mysite_url, 'http' ) ) {
            continue;
        }
        if ( ! isset( $mysite_seen[ $mysite_url ] ) ) {
            $mysite_response = wp_remote_get( $mysite_url, array( 'timeout' => 10 ) );
            $mysite_seen[ $mysite_url ] = is_wp_error( $mysite_response )
                ? $mysite_response->get_error_message()
                : wp_remote_retrieve_response_code( $mysite_response );
        }
        $mysite_status = $mysite_seen[ $mysite_url ];
        if ( ! is_int( $mysite_status ) || $mysite_status >= 400 ) {
            WP_CLI::log( get_permalink( $mysite_id ) . ' -> ' . $mysite_url . ' (' . $mysite_status . ')' );
        }
    }
}

Then run it:

wp eval-file check-links.php

Each line of output shows the post, the dead URL and the status code or error. The script checks each URL only once, even if ten posts use it.

A few notes before you trust the list:

  1. Some big sites block automated requests and answer with a 403 or 429. Open those links in your browser before you remove them.
  2. The script uses GET, since some servers refuse HEAD requests. It downloads each page, so on a large site run it at a quiet hour.
  3. It only reads post content. Links in menus, widgets and theme files aren't checked.

Method 3: an external crawler

Desktop and online link checkers crawl your site from the outside, like a visitor would. They see links in menus, footers and sidebars too, which the script above skips. Many have a free tier that caps the number of pages. They also add load while they crawl, so keep the speed low on shared hosting.

Fixing what you find

Once you have the list, work through it in this order:

  1. Your own pages first. If a post moved, update the link to the new address. If it's gone for good, link to the closest page that still exists, or remove the link.
  2. External pages that moved. Search the other site for the new address of the same page and update your link.
  3. External pages that are gone. Remove the link but keep the text, or link to another source that says the same thing.

In the block editor, select the linked text and use the link button in the toolbar to edit or remove it. For a URL used in many posts, WP-CLI's search-replace command can swap it everywhere. Run it with --dry-run first and take a database backup before the real run.

With Dead Link Finder

If you'd rather not run scripts, Dead Link Finder does the checking for you. Open Tools > Dead Link Finder and the first scan starts by itself. It checks posts, pages and any public post type you pick, in small background batches through WP-Cron, and checks each URL once even if fifty posts use it.

From the list you can edit a URL, unlink it (the text stays) or recheck it, all without opening the editor. You can dismiss false alarms and skip domains you never want checked. When you update a post, it's rescanned.

Related plugin: Dead Link Finder