Events Made Easy › Forums › Generic › link rel="canonical" has wrong url for event detail pages
- This topic has 10 replies, 2 voices, and was last updated 5 years, 10 months ago by Franky.
-
AuthorPosts
-
Fri 11 Jan 2019 at 10:13 #59407AnonymousInactive
The detail pages for a single event have a wrong value in the header <link rel=”canonical” />
It always has the url of the general events page configured in the settings
e.g. events page points to
yourdomain.tld/eventsA single event “Your event” will show in the browser the url
yourdomain.tld/events/your-event
but in the html source
<link rel=”canonical” href=”yourdomain.tld/events” />Fri 11 Jan 2019 at 11:46 #59412FrankyKeymasterEME removes the rel-canonical added by wp and adds its own (check with e.g. twentyseventeen themse or so). Probably your theme is adding another one. You should verify that. I’m guessing if you look at the resulting html-code, you’ll see 2 canonical lines …
Fri 11 Jan 2019 at 12:43 #59413AnonymousInactiveYou are right with the two canonical lines. But it still seems to be a general problem and not theme related.
The problem occures also with the default “Twenty …” themes.
I tested and could reproduce the beheavior with the themes “Twenty nineteen” and “Twenty seventeen” (default install)
Fri 11 Jan 2019 at 13:32 #59414FrankyKeymasterThen it is being added by a plugin. Maybe something yoast-alike?
Sun 13 Jan 2019 at 13:54 #59420AnonymousInactiveYou are correct with the plugin as cause.
the plugin causing this is “The SEO Framework”
I foud allready the function writing the canonical tag to html but unfortunally no way at he moment to disable this.
Sun 13 Jan 2019 at 14:23 #59421FrankyKeymasterIt is difficult for me to try and analyze all plugins that create and manage their own canonical url.
It seems that the SEO Framework also uses an undocumented filter called get_canonical_url.
You should ask them how to exclude a page from this.Sun 13 Jan 2019 at 14:54 #59422AnonymousInactiveSome findings for a possible solution:
“The SEO Framework” provides a filter for the canonical URL. It also provides a global DEFINE (‘THE_SEO_FRAMEWORK_PRESENT’) if it is active.
I was able to write a filter function which “overwrites” the canonical url if it is an single event or location page. Only side effect I have at the moment are two (identical) canonical statements in the html source.
Additional code required:
function eme_seo_canonical_url($arg_url) { if (eme_is_single_event_page()) { $event_id=eme_sanitize_request(get_query_var('event_id')); if (!eme_check_event_exists($event_id)) { return $arg_url; } $event=eme_get_event($event_id); return eme_event_url($event); } elseif (eme_is_single_location_page()) { $location_id=eme_sanitize_request(get_query_var('location_id')); if (!eme_check_location_exists($location_id)) { return $arg_url; } $location=eme_get_location($location_id); return eme_location_url($location); } return $arg_url; } add_filter ('the_seo_framework_rel_canonical_output', 'eme_seo_canonical_url');
Sun 13 Jan 2019 at 15:13 #59423FrankyKeymasterCan’t you use that filter to return an empty url? Maybe that helps …
Sun 13 Jan 2019 at 15:39 #59424AnonymousInactiveAn empty url for events and location pages seems to work. In this case I don’t get an canonical ref from The SEO Framework.
But another question:
Working code:
function eme_seo_framework_rel_canonical($arg_url) { if (eme_is_single_event_page()) { $event_id=eme_sanitize_request(get_query_var('event_id')); if (!eme_check_event_exists($event_id)) { return $arg_url; } return ""; // supress the canonical output for "The SEO framework" // $event=eme_get_event($event_id); // return eme_event_url($event); } elseif (eme_is_single_location_page()) { $location_id=eme_sanitize_request(get_query_var('location_id')); if (!eme_check_location_exists($location_id)) { return $arg_url; } return ""; // supress the canonical output for "The SEO framework" // $location=eme_get_location($location_id); // return eme_location_url($location); } return $arg_url; } add_filter ('the_seo_framework_rel_canonical_output', 'eme_seo_framework_rel_canonical');
Sun 13 Jan 2019 at 15:40 #59425AnonymousInactiveBut the other question:
Do you see an option to implemet this fix? Than it would be available for others as well.
Sun 13 Jan 2019 at 16:01 #59426FrankyKeymasterI can’t implement a fix for a plugin I don’t manage. But I can add a FAQ entry (like I did for yoast).
Edit: added to the FAQ -
AuthorPosts
- The forum ‘Generic’ is closed to new topics and replies.