{"id":131881,"date":"2014-10-05T08:00:00","date_gmt":"2014-10-05T12:00:00","guid":{"rendered":"http:\/\/premium.wpmudev.org\/blog\/?p=131881"},"modified":"2014-10-08T21:05:16","modified_gmt":"2014-10-09T01:05:16","slug":"style-external-links-wordpress-like-wikipedia","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/style-external-links-wordpress-like-wikipedia\/","title":{"rendered":"How to Style External Links in WordPress Like Wikipedia"},"content":{"rendered":"<p>Styling external links is common practice for many sites containing references, such as Wikipedia.<\/p>\n<p>For users, it&#8217;s a simple visual cue indicating that if you click a particular link you will\u00a0be\u00a0taken to another site.<\/p>\n<p>In today&#8217;s Weekend WordPress Project I&#8217;ll show you how to style all external links on your site.<!--more--><\/p>\n<figure id=\"attachment_132642\" class=\"wp-caption aligncenter\" data-caption=\"true\"><a rel=\"lightbox[131881]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/10\/external-icon-feature-image.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-large wp-image-132642\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/10\/external-icon-feature-image-700x218.jpg\" alt=\"External icon feature image\" width=\"700\" height=\"218\" \/><\/a><figcaption class=\"wp-caption-text\">Add icons to your external links.<\/figcaption><\/figure>\n<h2>How Wikipedia Styles Links<\/h2>\n<p>In case you&#8217;ve forgotten how Wikipedia styles its links, here&#8217;s an example from the WordPress page:<\/p>\n<figure id=\"attachment_132638\" class=\"wp-caption aligncenter\" data-caption=\"true\"><a rel=\"lightbox[131881]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/10\/wikipedia-external-link.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-132638\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/10\/wikipedia-external-link.png\" alt=\"Wikipedia external links\" width=\"630\" height=\"230\" \/><\/a><figcaption class=\"wp-caption-text\">Wikipedia external links.<\/figcaption><\/figure>\n<p>You&#8217;ll notice that a small icon sits next to each of the links mentioned in the References section of the WordPress page, indicating that the links, when clicked, will take you to a third-party website.<\/p>\n<h2>Styling External Links With Text<\/h2>\n<p>Firstly, let&#8217;s look at how to style your link with simple text.<\/p>\n<p>If you&#8217;re not already using a child theme, set one up now and then add the following code to your theme&#8217;s stylesheet.css file:<\/p>\n<p>{code type=php}<br \/>\na[href^=&#8221;http:\/\/&#8221;]:not([href*=&#8221;wpmu.dev&#8221;]):after,<br \/>\na[href^=&#8221;https:\/\/&#8221;]:not([href*=&#8221;wpmu.dev&#8221;]):after {<br \/>\ncontent: &#8220;(EXTERNAL LINK)&#8221;;<br \/>\npadding-left:5px;<br \/>\n}<\/p>\n<p>Your internal and external links will now look like this:<\/p>\n<figure id=\"attachment_132633\" class=\"wp-caption aligncenter\" data-caption=\"true\"><a rel=\"lightbox[131881]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/10\/external-link-with-text.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-132633\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/10\/external-link-with-text.png\" alt=\"External link with text.\" width=\"430\" height=\"210\" \/><\/a><figcaption class=\"wp-caption-text\">External link with text.<\/figcaption><\/figure>\n<p>Make sure you replace &#8220;wpmu.dev&#8221; with your website domain name.<\/p>\n<p>This code looks at each of the links on your site and compares them to your domain. If a link doesn&#8217;t match your domain, the text (EXTERNAL LINK) is added to the end of a link.<\/p>\n<h2>Styling External Links With an Icon<\/h2>\n<p>Now let&#8217;s add an icon to external links.<\/p>\n<p>Get yourself an appropriate icon. I like to use <a title=\"Flat Icon\" href=\"http:\/\/www.flaticon.com\/\" rel=\"noopener\" target=\"_blank\">Flat Icon<\/a>. You&#8217;ll then need to upload your icon to\u00a0your theme&#8217;s &#8220;images&#8221; folder.<\/p>\n<p>Next, add the following code to your stylesheet.css file:<\/p>\n<p>{code type=php}<br \/>\na[href^=&#8221;http:\/\/&#8221;]:not([href*=&#8221;wpmu.dev&#8221;]):after,<br \/>\na[href^=&#8221;https:\/\/&#8221;]:not([href*=&#8221;wpmu.dev&#8221;]):after {<br \/>\ncontent: &#8220;&#8221; url(&#8216;\/wp-content\/themes\/twentyfourteen\/images\/external-icon.png&#8217;);<br \/>\npadding-left:5px;<br \/>\n}<\/p>\n<p>Make sure you change &#8220;wpmu.dev&#8221; to your own domain name, and also update the URL to reflect the file name for your icon.<\/p>\n<p>The links on my test site now look like this:<\/p>\n<figure id=\"attachment_132634\" class=\"wp-caption aligncenter\" data-caption=\"true\"><a rel=\"lightbox[131881]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/10\/external-link-with-icon.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-132634\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2014\/10\/external-link-with-icon.png\" alt=\"External link with icon.\" width=\"410\" height=\"200\" \/><\/a><figcaption class=\"wp-caption-text\">External link with icon.<\/figcaption><\/figure>\n<p>You&#8217;ll notice that I&#8217;ve added padding to the icon so it doesn&#8217;t sit flush with the text.<\/p>\n<p>Thanks to the helpful members at <a title=\"Stack Exchange\" href=\"http:\/\/stackoverflow.com\/questions\/5379752\/css-style-external-links\" rel=\"noopener\" target=\"_blank\">Stack Exchange<\/a> for sharing their knowledge on how to style external links.<\/p>\n<p><em>Image credit: <a title=\"Dave Gandy\" href=\"http:\/\/www.flaticon.com\/free-icon\/external-link-symbol_25284\" rel=\"noopener\" target=\"_blank\">Dave Gandy<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Styling external links is common practice for many sites containing references, such as Wikipedia. For users, it&#8217;s a simple visual cue indicating that if you click a particular link you will\u00a0be\u00a0taken to another site. In today&#8217;s Weekend WordPress Project I&#8217;ll show you how to style all external links on your site.<\/p>\n","protected":false},"author":164650,"featured_media":132642,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[9798],"tutorials_categories":[],"class_list":["post-131881","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-weekend-wordpress-projects"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/131881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/164650"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=131881"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/131881\/revisions"}],"predecessor-version":[{"id":215710,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/131881\/revisions\/215710"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/132642"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=131881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=131881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=131881"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=131881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}