Noindex Specific Pages by ID
Adds a noindex,follow robots meta tag to specific pages or posts identified by their numeric ID, without touching any other URLs.
PHPby SnipCraft
php
<?php
if ( ! function_exists( 'scseed_noindex_by_id' ) ) :
function scseed_noindex_by_id() {
// Add the page or post IDs you want to noindex.
$noindex_ids = array( 0 ); // Replace 0 with real IDs, e.g. array( 42, 87, 123 )
if ( is_singular() && in_array( get_the_ID(), $noindex_ids, true ) ) {
echo '<meta name="robots" content="noindex, follow">' . PHP_EOL;
}
}
add_action( 'wp_head', 'scseed_noindex_by_id', 1 );
endif;#meta#noindex#pages#robots#seo