Events Made Easy Forums Generic link rel="canonical" has wrong url for event detail pages

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #59407
    Anonymous
    Inactive

    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/events

    A 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” />

    #59412
    Franky
    Keymaster

    EME 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 …

    #59413
    Anonymous
    Inactive

    You 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)

    #59414
    Franky
    Keymaster

    Then it is being added by a plugin. Maybe something yoast-alike?

    #59420
    Anonymous
    Inactive

    You 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.

    #59421
    Franky
    Keymaster

    It 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.

    #59422
    Anonymous
    Inactive

    Some 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');
    
    #59423
    Franky
    Keymaster

    Can’t you use that filter to return an empty url? Maybe that helps …

    #59424
    Anonymous
    Inactive

    An 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');
    
    
    #59425
    Anonymous
    Inactive

    But the other question:

    Do you see an option to implemet this fix? Than it would be available for others as well.

    #59426
    Franky
    Keymaster

    I 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

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘Generic’ is closed to new topics and replies.
Scroll to Top