Community Forums › Forums › Archived Forums › Design Tips and Tricks › rel=”alternate”
- This topic has 11 replies, 5 voices, and was last updated 10 years, 9 months ago by
DragNfLy.
-
AuthorPosts
-
January 13, 2014 at 6:54 am #84943
DragNfLy
MemberHi
When creating a new post, under Theme SEO settings tab, there is an option for "Canonical URL".
I would like to use the
rel="alternate" hreflang="x"
tag for some of my posts.Where would be the best place to add these.
I am using Genesis V2.0.2 with customised child sample V1.9 theme.
Any idea?
February 23, 2014 at 8:13 am #92011Susan
ModeratorAs you posted this a while back, I hope you were able to get your issue resolved. If not, please report back here, and I will escalate for you.
Thanks!
February 23, 2014 at 3:37 pm #92048DragNfLy
MemberHi Susan
I would appreciate some assistance re. the above issue.
Many Thanks
February 24, 2014 at 6:42 am #92112photastic
Membernevermind my reply :s
Trying to craft webstuff at Photastic Webdesign
Learning Genesis by solving unanswered topicsMarch 10, 2014 at 5:15 pm #94217DragNfLy
MemberHi Forum
I would appreciate some assistance re. the above issue. Any ideas?
Many Thanks
April 3, 2014 at 7:18 pm #98384DragNfLy
MemberHi Susan / Forum
I have been battling with this and have created a custom function to hook into wp_head.
Can anyone please let me know if this is the correct way to do this.
// Rel Alt Function add_action( 'wp_head', 'rel_alternate' ); function rel_alternate() { // Insert Rel=Alternate if post is if ( is_single( '150') ) { echo '<link rel="alternate" hreflang="af" href="#">'; } elseif ( is_single( '152') ) { echo '<link rel="alternate" hreflang="af" href="#">'; } }
Any comments welcome
April 4, 2014 at 7:47 am #98437nciske
MemberUsing conditionals like is_single( '150') isn't "wrong" per se, it's just really inflexible (though it's super quick if this is the only page this is needed for).
If these are posts on the same site:
WPML can enable these tags (and make managing them simpler to boot). Other translation plugins may support this or give you the info needed to generate these automatically.If they are translated posts on another site (or a mix of the two):
Ideally, you'd have some post meta (custom fields) to define the alternate versions which you'd loop through and output it dynamically.e.g.
The custom field rel_alternate would be an array of href and hreflang fields.The easiest way to do this would be with an Advanced Custom Fields repeater field, or another 'repeater' enabled custom field plugin.
Also, make sure you output a tag for the current page as well:
If you have multiple language versions of a URL, each language page must identify all language versions, including itself.
Source: https://support.google.com/webmasters/answer/189077?hl=en
I'm realizing I need this for a client project, so I may try to whip up a small plugin to do this. No promises, but I'll post a link here if I do 😉
Nick Ciske | https://luminfire.com/ | @nciske
Did I help you? Say thanks: http://bit.ly/1lahwy0April 5, 2014 at 6:01 am #98608DragNfLy
MemberThanks for your reply.
The Advanced Custom Post Type Repeater Addon is $25.00 AUD. So I'd rather follow my example above even though there are several pages; 30+ that will require hreflang tags.
I am however trying to get my head around the repeater fields. How would these hook into
wp_head
.This feature would be great addition to the 'Theme SEO settings tab' in Genesis the same way they offer to do 'Canonical'.... an afterthought for your plugin idea.
Thanks again
May 20, 2014 at 7:00 am #105995samw
MemberHi
Did you come up with a way of doing this on a by page or post basis?
I need to do this on a page by page basis - and with the Genesis default structure I cant see a simple way round having to create a new page template for every page and adding the code
Cheers
May 20, 2014 at 7:41 am #106003DragNfLy
MemberHi @samw
Yes, i did it the long way round, which is probably exactly what you require.
Code below in functions.php:
// MY REL ALTERNATE add_action( 'wp_head', 'rel_alternate' ); function rel_alternate() { // Insert Rel=Alternate if post is if ( is_single( '820') ) { echo '<link rel="alternate" hreflang="af" href="#" />'.PHP_EOL; } elseif ( is_single( '9150') ) { printf( '<link rel="alternate" hreflang="af" href="#" />').PHP_EOL; } }
I then add the Canonical URL to the Page settings 'Custom Canonical URL'
...and also exclude the 'hreflang page' from my Sitemap
I use the XML Sitemap & Google News feeds plugin which adds a 'Exclude from XML Sitemap' field to each post in the righ-hand sidebar.I am not sure if this is the correct way of doing this.
Good luck
🙂May 21, 2014 at 12:31 am #106126samw
MemberHi
Thanks
How are you adding the relevant hreflang markup to each post/page for the function? Does this function call this?
e.g. - All of these would go into the head or http header of a homepage using sub directories for multi region targeting
<link rel="alternate" href="site.com" hreflang="en" /> ( X default in English)
<link rel="alternate" href="site.com/kh" hreflang="en-kh" /> (Cambodia English)
<link rel="alternate" href="site.com/au" hreflang="en-au" /> (Aus English)
<link rel="alternate" href="site.com/kh" hreflang="km-kh" /> (Cambodia Khmer)I need to do this for all pages that are served to each region
It can also be done via sitemap which at least stops code bloat in pages and easier to change!
as explained here http://www.themediaflow.com/2012/08/an-international-seo-implementation-tale-sitemaps-relalternate-hreflangx/Cheers
May 21, 2014 at 10:13 am #106169DragNfLy
MemberYes, the 'add_action' calls this to 'head' of the page.
My scenario is a workaround as I am targeting 2 different languages for the same region. LOL > South Africa has 11 official languages. #hreflangnightmare
I would imaging there would be a different method for multi-region.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.