Skip to content

How do I add a class to all links? #1031

Answered by colinodell
ctessmer asked this question in Q&A
Discussion options

You must be logged in to vote

The Default Attributes extension does exactly this - no custom code required!

If you really did want to implement this with custom code, here's an example you could easily adapt - just change this part:

     public function onDocumentParsed(DocumentParsedEvent $event): void
     {
         $document = $event->getDocument();
         $walker = $document->walker();
         while ($event = $walker->next()) {
             $node = $event->getNode();
 
             // Only stop at Link nodes when we first encounter them
             if (!($node instanceof Link) || !$event->isEntering()) {
                 continue;
             }

-            $url = $node->getUrl();
-            if ($this->is…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ctessmer
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants