Gossamer Forum
Home : Products : Gossamer Links : Discussions :

how to insert rel="canonical" link with current URL

Quote Reply
how to insert rel="canonical" link with current URL
I'd like to insert the following into the head of the category template but I can't figure out what tag to use for the URL:

<link rel="canonical[/url]" href="<URL-of-the-current-category-page>" />

Does this perhaps require a global?

Thanks for any help!
Quote Reply
Re: [iplay] how to insert rel="canonical" link with current URL In reply to
Hi,

Are you just wanting this to point back to the category top level page? Where exactly are you going to be using it? That should really only be used if you are doing a mobile version of the same page - or different languages?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] how to insert rel="canonical" link with current URL In reply to
Thanks Andy.

The reason is to prevent "duplicate content" since at present bots believe

www.website.com/links/category/
and
www.website.com/links/category/index.htm

to be two different pages. The canonical should point to whichever is the current category page, without the "index.htm". So I wish to put it in the head of the category template for static building. It is not intended for different language versions or mobile (the site is responsive).

Thanks,
--Jo

Last edited by:

iplay: Jul 27, 2015, 3:24 AM
Quote Reply
Re: [iplay] how to insert rel="canonical" link with current URL In reply to
Hi,

Ah ok. In that case, you will probably need a global.

get_canonical
Code:
sub {
return $CFG->{build_root_url} . "/" . $DB->table('Category')->as_url( $_[0] ) . "/";
}

Call with:

Code:
<%get_canonical($Full_Name)%>

Untested, but should work fine

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] how to insert rel="canonical" link with current URL In reply to
You nailed it Andy! Worked first time.

Many thanksSmile

Thanks,
--Jo
Quote Reply
Re: [iplay] how to insert rel="canonical" link with current URL In reply to
BTW, not sure where I got that weird link in my original post:
<link rel="canonical[/url]" href="<URL-of-the-current-category-page>" />

I meant to put:
<link rel="canonical" href="<URL-of-the-current-category-page>" />

Sorry if that caused some confusion.Blush

Thanks,
--Jo
Quote Reply
Re: [iplay] how to insert rel="canonical" link with current URL In reply to
haha I guessed what you were after Angelic

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] how to insert rel="canonical" link with current URL In reply to
How are you Andy?! Any chance of doing the same thing for Detailed pages?

Thanks,
--Jo
Quote Reply
Re: [iplay] how to insert rel="canonical" link with current URL In reply to
Hi,

You should be able to do that with a new function:

get_current_detailed_url
Code:
sub {
return $CFG->{build_detail_url} . "/" . $DB->table("Links")->detailed_url($_[0]);
}

Then call in detailed.html with <%get_current_detailed_url($ID)%>

Be sure to check if <%detailed_url%> doesn't already exist in detailed.html, as I have a sneaky feeling it does (so no point re-creating it, as it just adds more work for the server Whistle)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] how to insert rel="canonical" link with current URL In reply to
Brilliant Andy and many thanks. Worked first time! Just got round to it Whistle

Thanks,
--Jo

Last edited by:

iplay: Jan 14, 2018, 12:58 AM