What’s the purpose of admin canonical tag?

I have searched through Google and WordPress developer resources, but nothing came up.

I understand the purpose of rel="canonical" tag in a website’s frontend (it’s part of the website SEO), but I fail to understand its purpose in WordPress Admin area (backend).

Example in a local WordPress installation:

<link id="wp-admin-canonical" rel="canonical" href="http://localhost/wordpress/wp-admin/plugins.php" />

What is their purpose in WordPress Admin area?

3 Answers
3

What is frontend & what is backend in WordPress?

The PHP CODE, SQL Queries etc. that are executed on your server is the backend & any HTML/CSS/JavaScript CODE that comes to the browser as a result, is the frontend.

So even though, some parts of your site’s “frontend” may be restricted by a password protected barrier, it’s still considered as frontend. It’s more accurate if you call it WordPress Admin Panel, instead of calling it the backend.

Why would WordPress Admin Panel pages need rel="canonical"?

Unless for a very very rare use case where you may make the admin pages public, there can be no SEO benefits from it. However, rel="canonical" can still be used (even for the admin panel pages): As part of the standard practice.

For a web page, rel="canonical" means:

The web page URL that is recognized as the go to URL for a collection of different pages having very similar or the same content.

Since this is the standard practice, even if you don’t get any SEO benefit from it, it’s still the right thing to do.

Where does it come from:

WordPress added wp_admin_canonical_url() function in WordPress 4.2. rel="canonical" part was there from the beginning & WordPress developers found no reason to remove it since then.

The original change came from the support ticket titled: Remove message parameters from admin URl’s in the browser address bar. And if you go through the discussion, you’ll see that the rel=canonical part was added as part of standard practice, nothing more.

Check the comment from the original developer:

  1. rel=canonical is a standard practice, and I think this is a good use of it.

Why WordPress needs the <link id="wp-admin-canonical" /> tag?

As evident from the above discussion, rel=canonical part of the <link> tag is only there for standard practice, however, the <link> tag:

<link id="wp-admin-canonical" rel="canonical" href="https://wordpress.stackexchange.com/questions/303448/__URL__" />

itself is functional. It was added to keep the URL & browser history clean from single-use query variable names.

For example, if you activate a Plugin, at the top of your admin panel, it gives you a message like:

Plugin activated.

After that, say you close the browser & open it back again later (or simply refresh the page). At that point, prior to WordPress 4.2 (if the browser is set to open the last opened tab), the page would still say:

Plugin activated

even though nothing really happened this time. Same applies when you use browser back button (because the message is shown in response to the single-use URL parameters from browser history as well).

This happens because WordPress redirects you to a URL like:

http://example.com/wp-admin/plugins.php?activate=true&plugin_status=all&paged=1&s=

after you activate a plugin. Notice the activate=true query string in the URL. This has no purpose other than showing you that “Plugin activated” message. So it has no use in the URL or browser history after the “Plugin activated” message is delivered to you.

That’s why, in WordPress 4.2 wp_admin_canonical_url() function was introduced, where <link id="wp-admin-canonical" /> tag keeps the reference to the canonical version of the URL without the single-use query variable part & then the JavaScript CODE from the function replaces it from the browser’s history entry.

As of writing this, there are 23 such single-use query variables that can be removed from the canonical URL from wp_removable_query_args() function:

'activate', 'activated', 'approved', 'deactivate', 'deleted',
'disabled', 'enabled', 'error', 'hotkeys_highlight_first', 
'hotkeys_highlight_last', 'locked', 'message', 'same', 'saved',
'settings-updated', 'skipped', 'spammed', 'trashed', 'unspammed', 
'untrashed', 'update', 'updated', 'wp-post-new-reload'

However, it can be extended from Plugins or Themes using the removable_query_args filter hook.

Leave a Comment