Dave Nichols Posted December 27, 2024 Share Posted December 27, 2024 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 December 28, 2024 Share Posted December 28, 2024 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 December 28, 2024 Share Posted December 28, 2024 @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...
Dave Nichols Posted 3 hours ago Author Share Posted 3 hours ago On 12/28/2024 at 12:10 PM, poljpocket said: 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"? I'm referring to the settings tab in the page edit form, in there is the 'Parent' field. When a new page is created this is blank (according to its template), but once populated you cannot make it blank again. I wanted to make it blank so that it no longer appeared as child in the parent page. I didn't want it as a child to anything as I had tweaked my system so that this parent found its children programmatically. My eventual workaround was to create a dummy hidden parent and link the relevant children to that. Setting the template to not allow children did not work retrospectively, so that was not a solution. My context was this: I had a site with a parent page (a race list) with lots of children (individual races), but each time a child page was added it had to be manually linked to its parent. Lots of different people where adding child pages and often 'forgot' to add the link. The child pages were all of a particular template type so I tweaked the parent page template code to find them dynamically. This resulted in duplication of the existing child links. So I wanted to clear them and found I could not. This is a link to the parent page - https://merciafr.club/races/ - the 'All Races' list is what is now created dynamically. 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