What are best practices for handling meta tags like "robots noindex nofollow" in PHP scripts?

When handling meta tags like "robots noindex nofollow" in PHP scripts, it is important to dynamically generate these meta tags based on certain conditions, such as preventing search engines from indexing or following certain pages. This can be achieved by checking specific conditions in your PHP script and outputting the appropriate meta tags in the HTML header section.

<?php
// Check if the page should have "robots noindex nofollow" meta tags
if ($shouldNoindexNofollow) {
    echo '<meta name="robots" content="noindex, nofollow">';
}
?>