Created
August 27, 2022 21:38
-
-
Save uaibo/cc473f5ff09202e6e08f3f8b654108a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
functions.php: | |
--------------- | |
``` | |
add_filter('the_content', 'external_links_nofollow_blank'); | |
function external_links_nofollow_blank($content) { | |
$content = preg_replace_callback('/]*href=["|\']([^"|\']*)["|\'][^>]*>([^<]*)<\/a>/i', function($m) { | |
if (strpos($m[1], home_url()) === false) | |
return 'href="'.$m[1].'" rel="nofollow" data-external="true" target="_blank">'.$m[2].'</a>'; | |
else | |
return 'href="'.$m[1].'">'.$m[2].'</a>'; | |
}, $content); | |
return $content; | |
} | |
``` | |
style.css: | |
----------- | |
``` | |
a[data-external="true"]{ | |
position:relative; | |
} | |
a[data-external="true"]::after{ | |
content:''; | |
background-image: url('images/external-link.svg'); | |
background-position: center; | |
background-repeat: no-repeat; | |
background-size: 20px 20px; | |
width:20px; | |
height:20px; | |
display:inline-block; | |
position:relative; | |
left:1px; | |
top:6px; | |
} | |
``` | |
svg: | |
------- | |
``` | |
<svg width="50px" height="50px" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"><path d="M38.288 10.297l1.414 1.415-14.99 14.99-1.414-1.414z"/><path d="M40 20h-2v-8h-8v-2h10z"/><path d="M35 38H15c-1.7 0-3-1.3-3-3V15c0-1.7 1.3-3 3-3h11v2H15c-.6 0-1 .4-1 1v20c0 .6.4 1 1 1h20c.6 0 1-.4 1-1V24h2v11c0 1.7-1.3 3-3 3z"/></svg> | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment