You need a noindex meta tag in the head section for all such posts:
<meta name="robots" content="noindex">
As the head section template (header.php) is common to all posts, you need to conditionally output the tag only when is_single() is true and the requested post has the 1147 category ID assigned to it.
The tag could be injected through the “wp_head” action, but IMO the tag is better off as one of the first tags encountered. The only way to do that is to add the conditional PHP directly to the header.php template. A third option is to have the server send a X-Robots-Tag: noindex
header response.
Oddly, though the meta tag output is necessarily outside of the “Loop”, the loop’s global $post object seems to already have the requested post object assigned, which can be passed directly to other post related functions. A more logical way to get the needed post ID is from get_queried_object_id()
. Use get_the_terms()
to check for the 1147 category because it will use a cached value if it can. wp_get_post_terms() will always hit the DB. It’s important for this code to be efficient because it runs for every front end request.
To send a header instead, use the ‘wp_headers’ filter, conditionally adding the noindex header to the passed array of header data.
Be aware that obeying the noindex tag is optional. Not all search bots will honor it. The major search engine bots like Google say they honor it. Also, Google for one will still crawl the page and follow any links it finds. It honors the noindex tag only by not listing the associated page in search results.