Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Preventing Self Closing <a> Tags

Go to End

4 Posts   1723 Views


Community Member, 5 Posts

30 September 2012 at 7:13am

Hoping there is an easy solution...

Using SilverStripe 3.0.2, and I'm trying to insert "Anchors" in to an HTMLEditorField. Something like <a name="anchor"></a>. However, when I save my page the tag ends up being converted to a self-closing <a> tag like this: <a name="anchor" />. This results in browsers thinking there's an unclosed tag on the page and causing some general bugginess.

Does anyone know what's happening here or how to prevent it? I think it's SilverStripe making this change and NOT TinyMCE (viewing the source in TinyMCE still shows separate opening and closing tags).

Tim Snadden

Community Member, 32 Posts

30 September 2012 at 8:13am

You may want to consider asking why you are doing this as there are likely better solutions. If you want to create the ability to link to parts of the page I would recommend adding ids (not names) to the elements you want to link to. I'm digging into my memory banks here but I seem to remember that a LONG time ago (maybe even as far as Netscape 3?) there were browsers that couldn't do internal page links to ids on elements and required and empty <a> element. Now you can just add an id to an element and link to it no problem.


Community Member, 5 Posts

1 October 2012 at 2:59am

Thanks Tim. I'm using anchors because that's what TinyMCE does and what my clients want. There's not an easy way to assign IDs to various headings using a WYSIWYG editor.

So, regardless of what's best... I still need to figure out how to prevent SS from making tags self-closing.



Community Member, 3 Posts

8 November 2012 at 8:00pm


this issue is solved in Silverstripe 3.0.3.


However if you need a quick fix:

Change this in HTMLValue.php Line 33: (HTMLValue::getContent())

return preg_replace (
array (
'<a $1></a>'