You could use the built-in functionality for $robotsNoIndex by putting your code into the end of init_add_crumbs.php and reworking it to set $robotsNoIndex under the conditions you desire.

There are other discussions for handling canonical matters also discussed elsewhere on the forum.