Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically remove empty [sitetree_link,id=] tags in Silverstripe?

I have come across a few large Silverstripe websites with broken internal site link tags in the $Content: [sitetree_link,id=]

For the link tag to work properly it needs an ID: [sitetree_link,id=123]

Without a numerical ID the link tag is simply rendered into the $Content HTML and causes a broken link: http://www.example.com/[sitetree_link,id=]

These websites often have hundreds of pages so manually removing these links would be incredibly time consuming.

One approach I thought of was writing some code OnPublish which removes the empty internal site link tags. But I wanted to check that a (better) solution doesn't already exist.

What is the best way to automatically remove empty [sitetree_link,id=] tags in Silverstripe?

like image 311
BaronGrivet Avatar asked Oct 22 '25 08:10

BaronGrivet


1 Answers

I would advise against automatically removing the links.

Removing the links will make them incorrectly point to the home page. It will also make it much more difficult to find and fix these broken links.

The SilverStripe admin has a broken links report that can be found at the following url:

[site-address]/admin/reports/BrokenLinksReport/

We can use this report to find and fix any broken links in our site.

like image 200
3dgoo Avatar answered Oct 23 '25 21:10

3dgoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!