Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wpmudev-sls/5567d07d07b7b55f6c9f74dc79e0cf65 to your computer and use it in GitHub Desktop.

Select an option

Save wpmudev-sls/5567d07d07b7b55f6c9f74dc79e0cf65 to your computer and use it in GitHub Desktop.
[SmartCrawl Pro] - Exclude specific category posts from indexing
<?php
/**
* Plugin Name: [SmartCrawl Pro] Exclude specific category posts from indexing
* Description: Exclude specific category posts from indexing.
* Author: Prashant @ WPMUDEV
* Task: SLS-6316
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
add_filter( 'wp_robots', 'wpmudev_exclude_specific_category_posts', 9999 );
function wpmudev_exclude_specific_category_posts( $robots ) {
if ( is_singular( 'post' ) && has_category( 'xy' ) ) { // Please change the category name and post type.
$robots['noindex'] = true;
$robots['nofollow'] = true;
}
return $robots;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment