Jump to content

Remove child links from a parent page


Dave Nichols
 Share

Recommended Posts

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

@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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...