I have successfully altered my SiteTree.php to add a metarobots tag by inserting the following into the MetaTags function it uses:
//custom-code: BOF Metarobot tags - Create and insert the meta robots tag
$tags .= "<meta name=\"robots\" content=\"" . Convert::raw2att($this->MetaRobotsTag) . "\" />\n";
//custom-code: EOF Metarobot tags - Create and insert the meta robots tag
This uses a new DropdownField called MetaRobotsTag, which I added to mysite/code/page.php using addFieldToTab for Root.Content.Metadata.
I'd like to know, is there a way I could have added the code I included above into the SiteTree.php MetaTags function without directly editing SiteTree.php. My guess is that I somehow could have extended the SiteTree.php MetaTags function in mysite/code/Page.php , but I can't figure out how to add a line to a pre-existing function. I understand a new class would add an entire new functionality. In this case I just need to add one line. Can anyone please suggest the cleanest way to do this, or was editing SiteTree.php the only way.
Please excuse if any of the above is a "dumb" question, I'm just learning SS and haven't gotten my head around all the different approaches to extending it.