With Relevanssi Premium, it would be a simple checking of the “Exclude this post from the index” checkbox from the post edit page.
With the free version, you can add a filter function on the relevanssi_do_not_index hook:
add_filter( 'relevanssi_do_not_index', 'rlv_post_exclusion', 10, 2 );
function rlv_post_exclusion( $block, $post_id ) {
$blocked_posts = array( 1, 2, 3, 4, 5 ); // List excluded post IDs here.
if ( in_array( $post_id, $blocked_posts, true ) ) {
$block = 'Excluded post';
}
return $block;
}
Thread Starter
TheViv
(@octotoot)
Thank you for your very fast reply.
Would a page be considered a post in this example, as long as I had the page ID?
Yes, all post types are counted as posts for this purpose.
Thread Starter
TheViv
(@octotoot)
Where in this code do I put the Page ID? In my case, it’s 7106
add_filter( 'relevanssi_do_not_index', 'rlv_post_exclusion', 10, 2 );
function rlv_post_exclusion( $block, $post_id ) {
$blocked_posts = array( 1, 2, 3, 4, 5 ); // List excluded post IDs here.
if ( in_array( $post_id, $blocked_posts, true ) ) {
$block = 'Excluded post';
}
return $block;
}
In the part where it says “List excluded post IDs here”. Replace the 1, 2, 3, 4, 5 with a list of IDs you want to exclude: array( 7106 );