Dave Nichols Posted Friday at 09:21 PM Share Posted Friday at 09:21 PM I have a parent page with lots of links to child pages. These pages are now set programmatically so I want to remove the children links from the parent page. I do not want to delete the children pages, just unlink them. I cannot find how to do that. How do I do it? Link to comment Share on other sites More sharing options...
poljpocket Posted 15 hours ago Share Posted 15 hours ago Hi Dave, can you elaborate a bit on what your goal is? I assume, you have the links to the child pages somewhere on the website (the part your visitors see), right? What do you mean by "unlink them"? Link to comment Share on other sites More sharing options...
Jo J Posted 12 hours ago Share Posted 12 hours ago @Dave NicholsI too am not clear, but if you want to remove anchor tags from a body I would do something like this: in ready.php wire()->addHookBefore('Pages::saveReady', function(HookEvent $event) { $page = $event->arguments(0); if ($page->name == 'parent-name') { $body = $page->body; // Use regex to remove anchor tags but keep the inner text $bodyWithoutAnchors = preg_replace_callback( '/<a[^>]*>(.*?)<\/a>/is', // Match <a> tags with content function ($matches) { return $matches[1]; // Return the inner text }, $body ); // Update the page body if ($body !== $bodyWithoutAnchors) { $page->body = $bodyWithoutAnchors; } } }); Backup your database & test with care as the above pattern will unlink ALL "<a>" tags. you may want to adjust the pattern to the children accordingly. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now