Created
December 5, 2012 12:15
-
-
Save roborourke/4215080 to your computer and use it in GitHub Desktop.
Adding an external link icon to entry titles
This file contains 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
/* show a little arrow image */ | |
.icon-external { | |
display: inline!important; | |
float: none!important; margin: 0 0 0 4px!important; | |
vertical-align: baseline!important; | |
} |
This file contains 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
<?php | |
// THIS IS ASSUMING YOU HAVE AN ICON IMAGE IN YOUR THEME! | |
// any post titles that don't link internally get an icon | |
add_filter( 'the_title', 'the_title_add_external_icon' ); | |
function the_title_add_external_icon( $title ) { | |
if ( get_post_type() != 'link' && ! strstr( get_permalink(), get_home_url() ) ) | |
$title .= '<img class="icon-external" src="' . get_stylesheet_directory_uri() . '/gfx/icon-external.png" title="External link" alt="(External link)" />'; | |
return $title; | |
} | |
// adds strip tags to esc_attr - get_the_title() is used in an attribute | |
// it MUST be wrapped in esc_attr() or esc_attr_e() etc... | |
add_filter( 'attribute_escape', 'attribute_escape_tags', 9, 2 ); | |
function attribute_escape_tags( $safe_text, $text ) { | |
$safe_text = strip_tags( $text ); | |
$safe_text = wp_check_invalid_utf8( $safe_text ); | |
$safe_text = _wp_specialchars( $safe_text, ENT_QUOTES ); | |
return $safe_text; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment