• Resolved Ibby

    (@ibby)


    Hi,
    We use Modern Events Calendar from Webnus for both public and staff calendars in our organisation. We have set our staff calendar’s category to noindex/nofollow/noarchive and restricted access using the Groups plugin. However, when we don’t noindex/nofollow/noarchive individual event listings, they are leaking onto search engines and can be accessible to viewers if staff forget to restrict access to the staff user group.
    Do you have a sample snippet we could add to our functions.php to automatically set noindex/nofollow/noarchive on individual event posts when we publish them as long as they are in a specific category?
    Thank you!

Viewing 1 replies (of 1 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Howdy!

    This should get you started; just replace the 42 and 'webnus_category' values at has_term() (I do not know which you need):

    add_filter( 'the_seo_framework_robots_meta_array', function( $meta, $args, $ignore ) {
    
    	if ( null === $args ) {
    		$post_id = is_singular() ? get_queried_object_id() : 0;
    	} elseif ( empty( $args['pta'] ) && empty( $args['taxonomy'] ) ) {
    		// Post edit screen, SEO Bar.
    		$post_id = $args['id'];
    	}
    
    	if ( empty( $post_id ) ) return $meta;
    
    	if ( has_term( 42, 'webnus_category', $post_id ) ) {
    		$meta['noindex'] = 'noindex';
    	}
    
    	return $meta;
    }, 10, 3 );

    See https://developer.www.ads-software.com/reference/functions/has_term/.

    You can optimize this snippet by filling in the post type name as the first parameter for is_singular().

Viewing 1 replies (of 1 total)
  • The topic ‘Auto noindex/nofollow/noarchive specific taxonomy’ is closed to new replies.