One of the WordPress plugins that I install on every one of my sites or my clients’ sites is Rank Math. When launching a site, one critical step is monitoring and correcting any visits to pages not found (404 errors). The plugin’s 404 monitor is a fantastic tool that needs to be enabled in the plugin settings. If your SEO consultant isn’t analyzing backlinks and monitoring 404 errors, find a new one!
Keep in mind that not all 404s are valid. Many are produced by bots that are crawling your site for vulnerabilities. However, many are valid. You should create content if the page doesn’t exist or redirect to the user to a relevant page if it does exist. I tend to monitor the report for the 404s most accessed (by sorting the report by Hits descending) and then analyzing the top results.
Rank Math 404 Monitor
The Rank Math 404 Monitor is simple, providing the URL that resulted in a 404, the number of times it was hit, and the last time it was accessed. By default, the report is sorted by the access time descending which is really quite useless.
Because I’m in this report so much, it’s both a pain and taxing to sort the report manually. I have to open the page, click Hits and it sorts ascending, then click Hits again to sort it descending. I want to open the report and, by default, have it sorted descending by the number of hits. Unfortunately, there’s no setting for this in the plugin.
How To Update Menu Links To Sort
Because I didn’t develop this plugin, I don’t want to make any edits to it since it’s updated often with new features. However, I can utilize jQuery to update the links as soon as the page is loaded… which doesn’t change the plugin at all. There are two menu locations for this link… the typical admin menu on the left and a shortcut menu in the header of the admin page. I want to update both.
Within my theme’s
functions.php page, I added the following code:
href attributes of both the admin menu and admin bar links.
It checks to ensure it’s not appending the query string multiple times in case the script runs more than once. Now, when I open WordPress Admin, each of the menu links is updated with the querystring to sort the list of 404s by hits descending by appending the querystring to the link. When I click on the report link, my report is sorted the way I want it to be: