From c4d82f014426b57be31ca3909b807652ab0a5f23 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 2 Sep 2026 15:25:52 +0800 Subject: [PATCH] Exclude anchor links from URL conversion --- src/ConvertKit_API_Traits.php | 5 +++++ tests/ConvertKitMethodsTest.php | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index 471c1b8..5267f5d 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -2682,6 +2682,11 @@ public function convert_relative_to_absolute_urls(\DOMNodeList $elements, string continue; } + // Skip if the attribute's value is an anchor. + if (strpos($element->getAttribute($attribute), '#') !== false) { + continue; + } + // Remove element if it's rocket-loader.min.js. Including it prevents landing page redirects from working. if (strpos($element->getAttribute($attribute), 'rocket-loader.min.js') !== false) { if ($element->parentNode instanceof \DOMNode) { diff --git a/tests/ConvertKitMethodsTest.php b/tests/ConvertKitMethodsTest.php index 5152d1c..2373c03 100644 --- a/tests/ConvertKitMethodsTest.php +++ b/tests/ConvertKitMethodsTest.php @@ -47,6 +47,7 @@ public function testConvertRelativeToAbsoluteUrls() Test + Anchor
Test
@@ -112,6 +113,12 @@ public function testConvertRelativeToAbsoluteUrls() '
Test
', $output ); + + // Assert string contains expected HTML elements that should not be modified. + $this->assertStringContainsString( + 'Anchor', + $output + ); } /**