{"id":924,"date":"2022-03-04T17:08:45","date_gmt":"2022-03-04T17:08:45","guid":{"rendered":"https:\/\/organicdigital.co\/blog\/?p=924"},"modified":"2026-09-21T12:05:16","modified_gmt":"2026-09-21T11:05:16","slug":"how-to-automatically-noindex-expired-event-pages-using-gtm","status":"publish","type":"post","link":"https:\/\/daveashworth.co\/blog\/how-to-automatically-noindex-expired-event-pages-using-gtm\/","title":{"rendered":"How To:\u00a0 Automatically Noindex Expired Event Pages Using GTM"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>TL;DR:<\/strong> <br>If your website has expired event pages that need to remain accessible to users but no longer need to appear in Google, you can use Google Tag Manager to noindex them automatically. I did this by reading the event date from the page, comparing it with the current date and adding a robots <code>noindex<\/code> directive once the event had passed. This should only be used where you\u2019ve deliberately decided expired events no longer need to remain indexed.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/daveashworth.co\/blog\/how-to-automatically-noindex-expired-event-pages-using-gtm\/#Why_I_needed_to_automatically_noindex_expired_events\" >Why I needed to automatically noindex expired events<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/daveashworth.co\/blog\/how-to-automatically-noindex-expired-event-pages-using-gtm\/#Step_1_%E2%80%93_Capture_the_event_date_with_GTM\" >Step 1 &#8211; Capture the event date with GTM<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/daveashworth.co\/blog\/how-to-automatically-noindex-expired-event-pages-using-gtm\/#Step_2_%E2%80%93_Identify_the_event_pages\" >Step 2 &#8211; Identify the event pages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/daveashworth.co\/blog\/how-to-automatically-noindex-expired-event-pages-using-gtm\/#Step_3_%E2%80%93_Add_noindex_when_the_event_date_has_passed\" >Step 3 &#8211; Add noindex when the event date has passed<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/daveashworth.co\/blog\/how-to-automatically-noindex-expired-event-pages-using-gtm\/#Should_you_noindex_expired_event_pages\" >Should you noindex expired event pages?<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_I_needed_to_automatically_noindex_expired_events\"><\/span>Why I needed to automatically noindex expired events<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Event websites can accumulate hundreds or even thousands of old event pages over time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes there&#8217;s a good reason to keep those pages available to users. A venue, for example, may want to retain an archive showing previous events rather than deleting the pages once each event has finished.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That doesn&#8217;t necessarily mean every expired event page needs to remain indexed by Google.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I encountered exactly this problem while working as a <a href=\"https:\/\/daveashworth.co\/skills\/google-tag-manager-consultant\/\">Google Tag Manager consultant<\/a> for a client whose website contained several years of historical events. The client wanted to keep the old event pages on the website, but we didn&#8217;t need those expired pages continuing to appear in search.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Manually adding a noindex tag to every event once it had passed wasn&#8217;t realistic. It would require ongoing housekeeping and would inevitably be forgotten.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead, I used Google Tag Manager to <strong>read the event date from the page, compare it with the current date and automatically add a robots noindex directive once the event had expired<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is a specific implementation of the broader technique I&#8217;ve covered in my guide to <a href=\"https:\/\/daveashworth.co\/blog\/how-to-implement-robots-noindex-tag-with-google-tag-manager\/\">adding a noindex tag using Google Tag Manager<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One important point before using this approach: <strong>don&#8217;t automatically noindex old content simply because it has a date in the past.<\/strong> An expired event page can still have search value, backlinks or useful historical information. This solution is for situations where you&#8217;ve deliberately decided those pages should remain accessible on the website but no longer need to appear in search.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_1_%E2%80%93_Capture_the_event_date_with_GTM\"><\/span>Step 1 &#8211; Capture the event date with GTM<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The first step was to grab the event date and time from each page.&nbsp; This was done by getting the datetime attribute from the particular div on the page \u2013 to do this, we set a variable which pulled in the DOM element using a CSS selector as followed:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"738\" height=\"601\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/event_date.jpg\" alt=\"Event Date\" class=\"wp-image-926\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/event_date.jpg 738w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/event_date-300x244.jpg 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/event_date-150x122.jpg 150w\" sizes=\"(max-width: 738px) 100vw, 738px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_2_%E2%80%93_Identify_the_event_pages\"><\/span>Step 2 &#8211; Identify the event pages<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I then created a trigger that detected when an event was being viewed as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"717\" height=\"398\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/event_url.jpg\" alt=\"Event URL\" class=\"wp-image-927\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/event_url.jpg 717w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/event_url-300x167.jpg 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/event_url-150x83.jpg 150w\" sizes=\"(max-width: 717px) 100vw, 717px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_3_%E2%80%93_Add_noindex_when_the_event_date_has_passed\"><\/span>Step 3 &#8211; Add noindex when the event date has passed<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">And that in turn fired the following custom html tag:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"693\" height=\"811\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/noindex_old_event.jpg\" alt=\"NoIndex Old Event\" class=\"wp-image-928\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/noindex_old_event.jpg 693w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/noindex_old_event-256x300.jpg 256w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2022\/03\/noindex_old_event-128x150.jpg 128w\" sizes=\"(max-width: 693px) 100vw, 693px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The code used is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script&gt;\nvar dateInPast = function(firstDate, secondDate) \n{\n  if (firstDate.setHours(0, 0, 0, 0) &lt;= secondDate.setHours(0, 0, 0, 0)) {\n    return true;\n  }\n  return false;\n};\n\nvar event_date = new Date({{Event Date}});\nvar today_date = new Date();\nvar in_the_past = dateInPast(event_date, today_date);\n\nif (in_the_past)\n{\t\n\tjQuery('meta&#91;name=\"robots\"]').remove();\n\tvar meta = document.createElement('meta');\n\tmeta.name = 'robots';\n\tmeta.content = 'noindex, follow';\n\tjQuery('head').append(meta);\n}\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, a function is created which passed in the event date and compares it to todays date.&nbsp; If that date is in the past, it returns true, and in turn, removes any existing robots tag and inserts a new one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you site doesn\u2019t support JQuery, you can use this code instead to add the new robots tag:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var metatag = document.createElement('meta');\nmetatag.setAttribute('name', 'robots');\nmetatag.content = 'noindex,follow';\ndocument.getElementsByTagName('head')&#91;0].appendChild(metatag);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Should_you_noindex_expired_event_pages\"><\/span>Should you noindex expired event pages?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Not every expired event should automatically be removed from Google&#8217;s index.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Some historical event pages continue to attract searches, earn links or provide useful information long after the event has finished. In those cases, retaining the page in search may make perfect sense.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This implementation was useful because the client had a large archive of old event pages they wanted to retain on the website, while having no particular reason for those pages to continue appearing in search.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using the event date meant the process could happen automatically rather than relying on somebody remembering to update each page manually.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your CMS can handle this directly, I&#8217;d generally implement the noindex logic there. If it can&#8217;t, GTM can provide a useful fallback for this type of automated rule.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A case study to show how to de-index content based on a certain date having passed.<\/p>\n","protected":false},"author":1,"featured_media":925,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4,13],"tags":[],"class_list":["post-924","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tag-manager","category-crawl-rate","category-on-page-seo"],"_links":{"self":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts\/924","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/comments?post=924"}],"version-history":[{"count":2,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts\/924\/revisions"}],"predecessor-version":[{"id":2451,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts\/924\/revisions\/2451"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/media\/925"}],"wp:attachment":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/media?parent=924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/categories?post=924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/tags?post=924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}