diff --git a/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php b/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php
index b02feb4d449d805d6c0d2798d184e9c0f6555cc1..df8e9b3c842be4dd913099e9c959b17270644e4b 100644
--- a/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php
+++ b/typo3/sysext/rte_ckeditor/Classes/Controller/BrowseLinksController.php
@@ -167,8 +167,10 @@ class BrowseLinksController extends AbstractLinkBrowserController
                 } else {
                     unset($this->linkAttributeValues['class']);
                 }
-                if (isset($classesAnchor[$this->displayedLinkHandlerId])
-                    && !in_array($linkClass, $classesAnchor[$this->displayedLinkHandlerId], true)
+                if (
+                    in_array($linkClass, $classesAnchor['all']) &&
+                    isset($classesAnchor[$this->displayedLinkHandlerId]) &&
+                    !in_array($linkClass, $classesAnchor[$this->displayedLinkHandlerId], true)
                 ) {
                     unset($this->linkAttributeValues['class']);
                 }