• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

rel=”alternate”

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › rel=”alternate”

This topic is: not resolved

Tagged: alternate, hreflang, rel=

  • This topic has 11 replies, 5 voices, and was last updated 11 years, 5 months ago by DragNfLy.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • January 13, 2014 at 6:54 am #84943
    DragNfLy
    Member

    Hi

    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 #92011
    Susan
    Moderator

    As 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 #92048
    DragNfLy
    Member

    Hi Susan

    I would appreciate some assistance re. the above issue.

    Many Thanks

    February 24, 2014 at 6:42 am #92112
    photastic
    Member

    nevermind my reply :s


    Trying to craft webstuff at Photastic Webdesign
    Learning Genesis by solving unanswered topics

    March 10, 2014 at 5:15 pm #94217
    DragNfLy
    Member

    Hi Forum

    I would appreciate some assistance re. the above issue. Any ideas?

    Many Thanks

    April 3, 2014 at 7:18 pm #98384
    DragNfLy
    Member

    Hi 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 #98437
    nciske
    Member

    Using 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/1lahwy0

    April 5, 2014 at 6:01 am #98608
    DragNfLy
    Member

    Thanks 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 #105995
    samw
    Member

    Hi

    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


    SEO & Online Marketing Consultant

    Metta3 | G+ | LinkedIn

    May 20, 2014 at 7:41 am #106003
    DragNfLy
    Member

    Hi @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 #106126
    samw
    Member

    Hi

    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


    SEO & Online Marketing Consultant

    Metta3 | G+ | LinkedIn

    May 21, 2014 at 10:13 am #106169
    DragNfLy
    Member

    Yes, 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.

  • Author
    Posts
Viewing 12 posts - 1 through 12 (of 12 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble