Does anyone know how to modify the WordPress canonical links to add a custom URL parameter?
I have a WordPress site with a page that queries a separate (non-Wordpress) database. I passed the URL parameter “pubID” to display individual books and it is working OK.
Example: http://www.uglyducklingpresse.org/catalog/browse/item/?pubID=63
But the individual book pages are not showing up properly in Google – the ?pubID parameter is stripped out.
I think maybe this is because all the item pages have the same auto-generated “canonical” URL link tag in the source – one with the “pubID” parameter stripped out.
Example: link rel=’canonical’ href=’http://www.uglyducklingpresse.org/catalog/browse/item/‘
Is there a way to perhaps edit .htaccess to add a custom URL parameter to WordPress, so that the parameter is not stripped out by permalinks and the “canonical” links?
Or maybe there’s another solution … Thank you for any ideas!
You should be able to replace WordPress’s
rel_canonical
action function with your own function in which (when your conditions are meet) you create a canonical link appending the query string variable. The following should work, although you’ll probably need to change the conditions to meet your needs.