Announcement

Collapse
No announcement yet.

Wordpress hreflang tags in head section on certain posts only

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Wordpress hreflang tags in head section on certain posts only

    Site owner has a Wordpress blog in English and a translation service for Spanish; however, to keep costs down, the posts with high traffic are being translated to Spanish manually and will be cut from the translation service. So each of those high-traffic posts have an English and Spanish version. So, we want to add an hreflang to the function.php, But, only for those pages we are manually translating. Hope this makes sense.

    Found the below, the only thing is it is going to get rather large as we add more and more of the high-traffic post. So, kind of two-fold question:

    1. Will the function below work? If not, can you help me adjust it to work?
    2. What happens as more and more blog ids are added to this function. Will performance be affected?

    PHP Code:
    function add_hreflang_tags() { if (is_front_page() || is_home()) { echo '<link rel="alternate" hreflang="es" href="https://es.example.com/blog" />'; } if (is_single('1234')) { echo '<link rel="alternate" hreflang="en-es" href="https://es.example.com/blog/" />'; } } add_action('wp_head''add_hreflang_tags'); 
    Just thought I'd give the forum a whirl, in the event anyone has dealt with something like this before.

    Thanks in advance for any advice,

    Jamie
    Jamie Donaldson
    JSDVS Web Design / Development
    Web Design | Web Development | E-commerce Design & Integration

    #2
    I would highly recommend not altering a core Wordpress file. Any update that replaces the file will break the change, and no copy of Wordpress should be left not updated. Assuming the goal is not possible with a trustworthy plugin, or in the software somewhere, then customization should be handled via a child theme so the primary files can continue receiving updates and only the child theme file contains a custom function.
    David Hubbard
    CIO
    Miva
    [email protected]
    http://www.miva.com

    Comment


      #3
      Thanks David. That is kind of what I was thinking.
      Jamie Donaldson
      JSDVS Web Design / Development
      Web Design | Web Development | E-commerce Design & Integration

      Comment


        #4
        Originally posted by jsdva View Post
        Site owner has a Wordpress blog in English and a translation service for Spanish; however, to keep costs down, the posts with high traffic are being translated to Spanish manually and will be cut from the translation service. So each of those high-traffic posts have an English and Spanish version. So, we want to add an hreflang to the function.php, But, only for those pages we are manually translating. Hope this makes sense.

        Found the below, the only thing is it is going to get rather large as we add more and more of the high-traffic post. So, kind of two-fold question:

        1. Will the function below work? If not, can you help me adjust it to work?
        2. What happens as more and more blog ids are added to this function. Will performance be affected?

        PHP Code:
        function add_hreflang_tags() { if (is_front_page() || is_home()) { echo '<link rel="alternate" hreflang="es" href="https://es.example.com/blog" />'; } if (is_single('1234')) { echo '<link rel="alternate" hreflang="en-es" href="https://es.example.com/blog/" />'; } } add_action('wp_head''add_hreflang_tags'); 
        Just thought I'd give the forum a whirl, in the event anyone has dealt with something like this before.

        Thanks in advance for any advice,

        Jamie
        Hi Jamie, as David mentioned, if this is a child theme function.php you could try it there but keep in mind even though it's its own file there might be an occasional update down the road that could still break it. Have you looked to see if there are any WordPress plug-in's that might do this for you?
        Leslie Kirk
        Miva Certified Developer
        Miva Merchant Specialist since 1997
        Previously of Webs Your Way
        (aka Leslie Nord leslienord)

        Email me: [email protected]
        www.lesliekirk.com

        Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

        Comment


          #5
          Thanks Leslie. Off hand not seeing any that will just display the Spanish hreflang on those Spanish posts and not display it on any non-spanish.
          Jamie Donaldson
          JSDVS Web Design / Development
          Web Design | Web Development | E-commerce Design & Integration

          Comment

          Working...
          X