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.
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
- Upload the
yt-broken-link-checker-litefolder to the/wp-content/plugins/directory - Activate the plugin through the 'Plugins' menu in WordPress
- Go to Tools → Broken Links to view results and configure settings
- Check the dashboard widget for a quick overview
How It Works
Automatic Scanning
- Plugin activates and schedules a weekly cron job
- Cron runs at the scheduled interval
- Scans all posts of selected post types
- Extracts URLs from post content (links and images)
- Checks each URL using
wp_remote_head() - Stores broken links in WordPress options
- 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://orhttps://)
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:
-
Statistics:
- Total broken links found
- When last scan was performed
- Time until next scheduled scan
-
Results Table:
- Post/Page title with edit link
- Broken URL
- HTTP status code or error message
- Quick action to edit the post
-
Dashboard Widget:
- Shows up to 5 broken links
- Link to view all results
- Last scan time
Manual Scan
- Go to Tools → Broken Links
- Click "Scan Now" button
- Wait for scan to complete (may take a while for many posts)
- 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):
-
yt_blc_options: Plugin settings
array( 'scan_frequency' => 'weekly', 'post_types' => array('post', 'page'), 'timeout' => 10 ) -
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 ) -
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 daytwicedaily: Every 12 hoursweekly: Once per week
Changing Frequency
When you change the frequency in settings:
- Old cron schedule is cleared
- New cron schedule is created
- 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
- Reduce post types: Only scan necessary post types
- Increase timeout: For slow external sites
- Less frequent scans: Weekly instead of daily
- 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:
- Use a real cron job (server-level)
- Use a plugin like WP Crontrol
- Set up external monitoring service
Scans timing out?
If scans never complete:
- Increase PHP max_execution_time
- Reduce number of post types
- Increase request timeout
- Run manual scans during off-peak hours
False positives?
Some sites may block automated requests:
- Check manually to verify
- Some sites require specific headers
- Firewall may block the server's IP
- 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
- Schedule during low traffic: Choose frequency based on site traffic
- Review regularly: Check dashboard widget weekly
- Fix promptly: Broken links hurt SEO and user experience
- Export data: Screenshot or note broken links before fixing
- Re-scan after fixes: Verify links are now working
- 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:
- All plugin options are removed
- Cron job is cleared
- WordPress cache is flushed
- No data is left behind
Requirements
- WordPress 5.8 or higher
- PHP 7.4 or higher
- Server must allow outgoing HTTP requests
wp_cronmust 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
- Website: https://krasenslavov.com
- GitHub: https://github.com/krasenslavov
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