Skip to content

Commit 7ce9672

Browse files
committed
Exclude rel=nofollow links from prefetch/prerender
1 parent 032f1f2 commit 7ce9672

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

plugins/speculation-rules/helper.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function plsr_get_speculation_rules() {
7777
'source' => 'document',
7878
'where' => array(
7979
'and' => array(
80-
// Prerender any URLs within the same site.
80+
// Include any URLs within the same site.
8181
array(
8282
'href_matches' => $prefixer->prefix_path_pattern( '/*' ),
8383
),
@@ -87,6 +87,12 @@ function plsr_get_speculation_rules() {
8787
'href_matches' => $href_exclude_paths,
8888
),
8989
),
90+
// Also exclude rel=nofollow links, as plugins like WooCommerce attribute their add-to-cart links (which should buttons).
91+
array(
92+
'not' => array(
93+
'selector_matches' => 'a[rel=nofollow]',
94+
),
95+
),
9096
),
9197
),
9298
'eagerness' => $eagerness,

tests/plugins/speculation-rules/speculation-rules-helper-test.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function test_plsr_get_speculation_rules_prerender() {
100100
$rules = plsr_get_speculation_rules();
101101

102102
$this->assertArrayHasKey( 'prerender', $rules );
103-
$this->assertCount( 3, $rules['prerender'][0]['where']['and'] );
103+
$this->assertCount( 4, $rules['prerender'][0]['where']['and'] );
104104
}
105105

106106
/**
@@ -112,7 +112,7 @@ public function test_plsr_get_speculation_rules_prefetch() {
112112
$rules = plsr_get_speculation_rules();
113113

114114
$this->assertArrayHasKey( 'prefetch', $rules );
115-
$this->assertCount( 2, $rules['prefetch'][0]['where']['and'] );
115+
$this->assertCount( 3, $rules['prefetch'][0]['where']['and'] );
116116
}
117117

118118
/**

0 commit comments

Comments
 (0)