Thursday, October 17, 2019
  • Index
  •  » Code Exchange
  •  » How to add multiple instances of a hreflang tag throughout sitemap.xml

#1 2019-10-09 09:43:12 am

jdy122
Member
Registered: 2019-10-08
Posts: 1

How to add multiple instances of a hreflang tag throughout sitemap.xml

Using TextWrangler, I am trying to add an hreflang tag to each URL throughout a large sitemap.

Is there a script that can add:

<xhtml:link rel="alternate" hreflang="en-ca" href="https://mywebsite.com/en_ca/" />
<xhtml:link rel="alternate" hreflang="en-us" href="https://mywebsite.com/en_us/" />

After each instance in the document there is the <loc> URL </loc> tag, as seen in the below example:

  <url>
    <loc>https://mywebsite.com/en_ca/product-1/</loc>
    <lastmod>2019-09-19</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
  </url>

And at the same time pull in the subfolder (/product-1/) from the URL found in the <loc> tag.

The goal would be to have each url tag look like this after:

  <url>
    <loc>https://mywebsite.com/en_ca/product-1/</loc>
   <xhtml:link rel="alternate" hreflang="en-ca" href="https://mywebsite.com/en_ca/product-1/" />
   <xhtml:link rel="alternate" hreflang="en-us" href="https://mywebsite.com/en_us/product-1/" />
    <lastmod>2019-09-19</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.8</priority>
  </url>

Essentially:
1) Input hreflang tag after <loc> tag
2) Grab everything after /en_ca/ in the <loc> tag and add that after /en_ca/ and /en_us/ in the added hreflang tag as well.

I'm looking for anyone who knows of script to accomplish this, or can tell me if it is even possible to do.

Thank you.

Last edited by jdy122 (2019-10-09 09:44:58 am)


Filed under: textwrangler

Offline

 
  • Index
  •  » Code Exchange
  •  » How to add multiple instances of a hreflang tag throughout sitemap.xml

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)