Skip to content

Commit 5a44f05

Browse files
authored
Merge pull request #49 from justcoded/hotfix/update-autoptimize-regex
update regex
2 parents 836ba6f + f802d25 commit 5a44f05

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

framework/Supports/Autoptimize.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,19 @@ public function add_external_links_target_rel( $content ) {
145145
preg_match( '#http(s)?\:\/\/(([a-z0-9\_\-\.]+)\.([a-z0-9]{2,5}))\/?#', site_url(), $site_domain );
146146

147147
foreach ( $matches[0] as $tag ) {
148-
if ( preg_match( '#href="(http\:\/\/|https\:\/\/|\/\/)(([a-z0-9\_\-\.]+)\.([a-z0-9]{2,5}))\/#Usmi', $tag, $domain ) ) {
148+
if ( preg_match( '#href="(http\:\/\/|https\:\/\/|\/\/)(([a-z0-9\_\-\.]+)\.([a-z0-9]{2,5}))(\/|\")#Usmi', $tag, $domain ) ) {
149149
if ( false !== strpos( $domain[2], $site_domain[2] ) ) {
150150
continue;
151151
}
152152

153153
$basic_tag = $tag;
154154

155155
if ( ! preg_match( '#rel="(.*)"#Usmi', $basic_tag, $rel_domain ) ) {
156-
$tag = str_replace( $domain[0], $domain[0] . ' rel="noopener noreferrer"', $tag );
156+
$tag = str_replace( $domain[0], 'rel="noopener noreferrer" ' . $domain[0], $tag );
157157
}
158158

159159
if ( ! preg_match( '#target="(.*)"#Usmi', $basic_tag, $target_domain ) ) {
160-
$tag = str_replace( $domain[0], $domain[0] . ' target="_blank"', $tag );
160+
$tag = str_replace( $domain[0], 'target="_blank" ' . $domain[0], $tag );
161161
}
162162

163163
$content = str_replace( $basic_tag, $tag, $content );

0 commit comments

Comments
 (0)