External link icon shortcode preference

Quick how to.

There are a number of WordPress plugins that will allow you to apply external link icons automatically, but that’s not really my preference.

I like to use an external link icon if a link opens in a new window. We avoid opening links in a new window, in general. But there are a few instances where it makes sense. When we do, we like to signal to the user that this will happen.

So, these days, on WordPress, we like to add a custom shortcode to do this! We use this snippet to call Font Awesome:

add_action( 'wp_enqueue_scripts', 'add_font_awesome' );

function add_font_awesome() {
wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css

' );

And we use this snippet to create the shortcode:

// function for shortcode
function external_link_icon() { 
// Output
$message = '<i class="fa fa-external-link"></i>'; 
// Output printed
return $message;
// register shortcode
add_shortcode('put_custom_name_here', 'external_link_icon');

Similar Posts