Enjoying these plugins? ☕ Buy me a coffee to support ongoing development.

Broken Link Checker Lite

A lightweight WordPress plugin that periodically scans your content for broken links and displays them in an easy-to-use dashboard widget. Perfect for maintaining site health and SEO.

Single File v1.0.0 Updated 2 months ago

YT Broken Link Checker Lite

A lightweight WordPress plugin that periodically scans your content for broken links and displays them in an easy-to-use dashboard widget. Perfect for maintaining site health and SEO.

Features

  • Automatic Scanning: Weekly cron job scans all published posts and pages
  • Manual Scan: Run scans on-demand with a single click
  • Dashboard Widget: Quick overview of broken links on the main dashboard
  • URL Validation: Uses wp_remote_head() to check link status
  • Detailed Reports: View broken links with post titles, URLs, and status codes
  • Configurable Frequency: Choose between daily, twice daily, or weekly scans
  • Post Type Selection: Scan posts, pages, or any custom post type
  • Timeout Control: Adjust request timeout (5-30 seconds)
  • Search & Filter: Quickly find specific broken links
  • Click to Copy: Click any URL to copy it to clipboard
  • Responsive Design: Mobile-friendly admin interface
  • WPCS Compliant: Follows WordPress coding standards

Installation

  1. Upload the yt-broken-link-checker-lite folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. Go to Tools → Broken Links to view results and configure settings
  4. Check the dashboard widget for a quick overview

How It Works

Automatic Scanning

  1. Plugin activates and schedules a weekly cron job
  2. Cron runs at the scheduled interval
  3. Scans all posts of selected post types
  4. Extracts URLs from post content (links and images)
  5. Checks each URL using wp_remote_head()
  6. Stores broken links in WordPress options
  7. Displays results in dashboard widget and admin page

Link Checking

  • Uses wp_remote_head() for HEAD requests (faster than full GET)
  • Follows redirects (up to 5 hops)
  • Configurable timeout (default: 10 seconds)
  • Checks both <a> tags (href) and <img> tags (src)
  • Only checks external URLs (starting with http:// or https://)

Status Codes

  • 200-399: Link is working ✓
  • 400-599: Link is broken ✗
  • Error: Network error or timeout

Usage

Viewing Broken Links

Navigate to Tools → Broken Links to see:

  1. Statistics:

    • Total broken links found
    • When last scan was performed
    • Time until next scheduled scan
  2. Results Table:

    • Post/Page title with edit link
    • Broken URL
    • HTTP status code or error message
    • Quick action to edit the post
  3. Dashboard Widget:

    • Shows up to 5 broken links
    • Link to view all results
    • Last scan time

Manual Scan

  1. Go to Tools → Broken Links
  2. Click "Scan Now" button
  3. Wait for scan to complete (may take a while for many posts)
  4. View results

Configuring Settings

Scan Frequency:

  • Daily: Scans once per day
  • Twice Daily: Scans every 12 hours
  • Weekly: Scans once per week (default)

Post Types to Scan:

  • Select which post types to check
  • Default: Posts and Pages
  • Works with custom post types

Request Timeout:

  • How long to wait for a response
  • Range: 5-30 seconds
  • Default: 10 seconds

Clearing Results

Click "Clear Results" button to remove all broken link data. Useful after fixing links or for a fresh start.

File Structure

yt-broken-link-checker-lite/
├── class-yt-broken-link-checker-lite.php    # Main plugin file (~650 lines)
├── assets/
│   ├── css/
│   │   └── yt-blc-admin.css                 # Admin UI styles
│   └── js/
│       └── yt-blc-admin.js                  # Admin interactions
└── README.md                                 # This file

Prefix Convention

All functions, classes, and elements use the yt_blc prefix:

  • Class: YT_Broken_Link_Checker_Lite
  • Constants: YT_BROKEN_LINK_CHECKER_*
  • Functions: yt_blc_*
  • CSS Classes: .yt-blc-*
  • JavaScript Object: ytBlcAdmin
  • Cron Hook: yt_blc_scan_links
  • Options: yt_blc_options, yt_blc_broken_links, yt_blc_last_scan
  • Text Domain: yt-broken-link-checker-lite

Database Storage

The plugin stores data in WordPress options (no custom tables):

  1. yt_blc_options: Plugin settings

    array(
       'scan_frequency' => 'weekly',
       'post_types' => array('post', 'page'),
       'timeout' => 10
    )
  2. yt_blc_broken_links: Array of broken links

    array(
       array(
           'post_id' => 123,
           'url' => 'https://example.com/broken',
           'status_code' => 404,
           'error' => ''
       ),
       // ... more broken links
    )
  3. yt_blc_last_scan: Unix timestamp of last scan

Cron Implementation

Scheduling

// On activation
wp_schedule_event( time(), 'weekly', 'yt_blc_scan_links' );

// Hook
add_action( 'yt_blc_scan_links', 'scan_all_links' );

Frequencies

  • daily: Once per day
  • twicedaily: Every 12 hours
  • weekly: Once per week

Changing Frequency

When you change the frequency in settings:

  1. Old cron schedule is cleared
  2. New cron schedule is created
  3. Takes effect immediately

Security Features

  • Capability Checks: All admin actions require manage_options
  • Nonce Verification: CSRF protection on all forms
  • Input Sanitization: All inputs sanitized before storage
  • Output Escaping: All output properly escaped
  • Safe HTTP Requests: Uses wp_remote_head() with timeouts
  • User Agent: Custom user agent for identification

Performance Considerations

Scan Performance

  • Uses HEAD requests (faster than GET)
  • Processes posts sequentially
  • Configurable timeout prevents hanging
  • Only scans published posts
  • Caches results until next scan

Impact on Site

  • Cron job runs in background: Doesn't affect front-end
  • No database tables: Uses standard WordPress options
  • Minimal queries: Loads all posts once, then processes
  • Throttled requests: Respects timeout settings

Optimization Tips

  1. Reduce post types: Only scan necessary post types
  2. Increase timeout: For slow external sites
  3. Less frequent scans: Weekly instead of daily
  4. Exclude old posts: Manually if needed (custom code)

Troubleshooting

Cron not running?

WordPress cron requires site visits to trigger. If your site has low traffic:

  1. Use a real cron job (server-level)
  2. Use a plugin like WP Crontrol
  3. Set up external monitoring service

Scans timing out?

If scans never complete:

  1. Increase PHP max_execution_time
  2. Reduce number of post types
  3. Increase request timeout
  4. Run manual scans during off-peak hours

False positives?

Some sites may block automated requests:

  1. Check manually to verify
  2. Some sites require specific headers
  3. Firewall may block the server's IP
  4. Rate limiting may cause temporary failures

Links not detected?

The plugin extracts links from:

  • <a href="..."> tags
  • <img src="..."> tags

It does NOT check:

  • Links in shortcodes (unless they render)
  • JavaScript-generated links
  • Links in custom fields
  • Links in widgets

Best Practices

  1. Schedule during low traffic: Choose frequency based on site traffic
  2. Review regularly: Check dashboard widget weekly
  3. Fix promptly: Broken links hurt SEO and user experience
  4. Export data: Screenshot or note broken links before fixing
  5. Re-scan after fixes: Verify links are now working
  6. Monitor patterns: Repeated broken links may indicate an issue

Limitations

Current Version

  • HEAD requests only: Some servers don't support HEAD properly
  • No link statistics: Doesn't track when links broke
  • No notifications: Doesn't email about broken links
  • No link editing: Must manually edit posts
  • No link replacement: Can't find and replace links
  • No external link management: Just detection, not management

Not Included

  • Email notifications
  • Link statistics/history
  • Bulk link editing
  • Link replacement
  • External site monitoring
  • API integration
  • Custom headers for requests
  • Proxy support

Uninstallation

When the plugin is deleted via WordPress admin:

  1. All plugin options are removed
  2. Cron job is cleared
  3. WordPress cache is flushed
  4. No data is left behind

Requirements

  • WordPress 5.8 or higher
  • PHP 7.4 or higher
  • Server must allow outgoing HTTP requests
  • wp_cron must be working (or real cron setup)

Complexity

  • Main PHP File: ~650 lines (with comments)
  • CSS File: ~170 lines
  • JS File: ~145 lines
  • Total: ~965 lines across all files

FAQ

How often should I scan for broken links?

For most sites, weekly is sufficient. High-traffic sites or sites with frequently changing content may benefit from daily scans.

Does it slow down my site?

No! The scanning happens in the background via cron and doesn't affect your front-end performance.

Can I test specific URLs?

Not directly through the plugin. You would need to add a post with that URL and run a scan.

What happens to broken links from deleted posts?

When you delete a post, its broken links remain in the results until the next scan or until you clear results.

Can I export the results?

Not currently. You can copy the data from the admin page or use a screenshot.

Does it check internal links?

No, it only checks external links (starting with http:// or https://). Internal links should always work if your site is configured correctly.

Will it detect links in custom fields?

No, it only scans the main post content (post_content). Custom fields and meta data are not checked.

Can I schedule scans for specific times?

Not through the plugin UI. You can modify the cron schedule using WP-CLI or a cron management plugin.

Changelog

1.0.0

  • Initial release
  • Weekly automated scanning
  • Dashboard widget
  • Manual scan option
  • Configurable scan frequency
  • Post type selection
  • Request timeout control
  • Search and filter functionality
  • Click to copy URLs
  • Responsive admin design

License

GPL v2 or later

Author

Krasen Slavov

Support

For issues and feature requests, please visit the GitHub repository.

Future Enhancements

Potential features for future versions:

  • Email notifications for broken links
  • Link editing/replacement interface
  • Link statistics and history
  • Bulk link operations
  • Custom HTTP headers support
  • Exclude specific URLs or domains
  • REST API endpoints
  • White-label reporting
  • Integration with Google Search Console
  • Link monitoring dashboard