{"id":1958528,"date":"2023-11-09T06:53:00","date_gmt":"2023-11-09T11:53:00","guid":{"rendered":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/?p=1958528"},"modified":"2023-11-09T06:53:01","modified_gmt":"2023-11-09T11:53:01","slug":"how-to-remove-indexing-from-recurring-event-occurrences-on-google","status":"publish","type":"post","link":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/how-to-remove-indexing-from-recurring-event-occurrences-on-google\/","title":{"rendered":"How to Remove Indexing from Recurring Event Occurrences on Google"},"content":{"rendered":"\n<p>Our support team answers many questions every day, and recently, we&#8217;ve received some questions about how to automatically add a noindex tag for all occurrences of a recurring event.<\/p>\n\n\n\n<p>In one case, a user mentioned that they prefer creating a page for the event and not having all recurring event occurrences indexed by Google.<\/p>\n\n\n\n<p>The good news is that it is possible to achieve this with the following PHP snippet:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_action( &#039;wp_head&#039;, &#039;tec_add_nofollow_to_recurring_events&#039; );\n\n\/**\n * Add &#039;nofollow&#039; to recurring events, except for the first instance.\n * \n * @return void\n *\/\nfunction tec_add_nofollow_to_recurring_events() {\n    \/\/ Bail if ECP is not active.\n    if ( ! class_exists( &#039;Tribe__Events__Pro__Main&#039; ) ) {\n\t\treturn;\n    }\n\n    \/\/ Get the post ID.\n    $event_id = get_the_ID();\n\n    \/\/ Bail, if it&#039;s not an event.\n    if ( get_post_type( $event_id ) != &quot;tribe_events&quot; ) {\n\t\treturn;\n    }\n\t\n    \/\/ Bail, if it&#039;s not a single event\n    if ( ! is_single() ){\n        return;\n    }\n\t\/\/ If it&#039;s a recurring event, add the noindex meta tag\n    if ( tribe_is_recurring_event($event_id) ) {\n\t\techo &#039;&lt;meta name=&quot;robots&quot; id=&quot;tec_noindex&quot; content=&quot;noindex, follow&quot; \/&gt;&#039; . &quot;\\n&quot;;\n    }\n}\n<\/pre><\/div>\n\n\n<p>Although that works for the above scenario, we do see other scenarios around this request as well.<\/p>\n\n\n\n<p>If you&#8217;re looking to have only the first recurrence indexed by Google but not all the subsequent ones, you&#8217;ll need to tweak that code not to include the noindex tag for the first event occurrence.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nadd_action( &#039;wp_head&#039;, &#039;tec_add_nofollow_to_recurring_events&#039; );\n\n\/**\n * Add &#039;nofollow&#039; to recurring events, except for the first instance.\n * \n * @return void\n *\/\nfunction tec_add_nofollow_to_recurring_events() {\n    \/\/ Bail if ECP is not active.\n    if ( ! class_exists( &#039;Tribe__Events__Pro__Main&#039; ) ) {\n\t\treturn;\n    }\n\n    \/\/ Get the post ID.\n    $event_id = get_the_ID();\n\n    \/\/ Bail, if it&#039;s not an event.\n    if ( get_post_type( $event_id ) != &quot;tribe_events&quot; ) {\n\t\treturn;\n    }\n\t\n    \/\/ Bail, if it&#039;s not a single event\n    if ( ! is_single() ){\n        return;\n    }\n\t\n    if ( tribe_is_recurring_event($event_id) ){\n        \/\/ Get the post object.\n\t    $post = get_post( $event_id );\n\t\n\t    \/\/ Check if the event is the first in the recurrence.\n\t    $is_first = \\TEC\\Events\\Custom_Tables\\V1\\Models\\Occurrence::is_first( $post-&gt;_tec_occurrence );\n\n\t    \/\/ If it&#039;s not the first recurrence, add the noindex meta tag\n\t    if ( !$is_first ) {\n\t\t    echo &#039;&lt;meta name=&quot;robots&quot; id=&quot;tec_noindex&quot; content=&quot;noindex, follow&quot; \/&gt;&#039; . &quot;\\n&quot;;\n\t    }\n    }\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Our support team answers many questions every day, and recently, we&#8217;ve received some questions about how to automatically add a noindex tag for all occurrences of a recurring event. In one case, a user mentioned that they prefer creating a page for the event and not having all recurring event occurrences indexed by Google. The&#8230;<\/p>\n","protected":false},"author":31,"featured_media":1955565,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_swpsp_post_exclude":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"ep_exclude_from_search":false,"footnotes":""},"categories":[59,79],"tags":[204],"stellar-product-taxonomy":[],"class_list":["post-1958528","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-customizing-resources","category-snippets","tag-seo"],"acf":[],"taxonomy_info":{"category":[{"value":59,"label":"PHP &amp; Functions"},{"value":79,"label":"Snippets"}],"post_tag":[{"value":204,"label":"SEO"}]},"featured_image_src_large":["https:\/\/images.theeventscalendar.com\/kb\/uploads\/2023\/02\/social-share-1024x538.png",1024,538,true],"author_info":{"display_name":"Guga Alves","author_link":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/author\/gugatheeventscalendar-com\/"},"comment_info":0,"category_info":[{"term_id":59,"name":"PHP &amp; Functions","slug":"customizing-resources","term_group":0,"term_taxonomy_id":59,"taxonomy":"category","description":"","parent":24,"count":101,"filter":"raw","term_order":"0","cat_ID":59,"category_count":101,"category_description":"","cat_name":"PHP &amp; Functions","category_nicename":"customizing-resources","category_parent":24},{"term_id":79,"name":"Snippets","slug":"snippets","term_group":0,"term_taxonomy_id":79,"taxonomy":"category","description":"","parent":0,"count":136,"filter":"raw","term_order":"0","cat_ID":79,"category_count":136,"category_description":"","cat_name":"Snippets","category_nicename":"snippets","category_parent":0}],"tag_info":[{"term_id":204,"name":"SEO","slug":"seo","term_group":0,"term_taxonomy_id":204,"taxonomy":"post_tag","description":"","parent":0,"count":11,"filter":"raw","term_order":"0"}],"_links":{"self":[{"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1958528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1958528"}],"version-history":[{"count":4,"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1958528\/revisions"}],"predecessor-version":[{"id":1958533,"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1958528\/revisions\/1958533"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1955565"}],"wp:attachment":[{"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1958528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1958528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1958528"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/dev.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1958528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}