Skip to content

Instantly share code, notes, and snippets.

@pagelab
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save pagelab/9770932 to your computer and use it in GitHub Desktop.

Select an option

Save pagelab/9770932 to your computer and use it in GitHub Desktop.
Two simple functions to allow better smilies in WordPress. Drop one of them (not both) in your functions.php
/**
* Filter smilies to allow SVG format with PNG fallback (IE7-IE8)
* @license http://www.gnu.org/licenses/gpl-3.0.html
* @since 1.0.0
*/
add_filter('smilies_src','my_svg_smilies_src', 1, 10);
function my_svg_smilies_src($img_src, $img, $siteurl) {
$img = rtrim($img, "gif"); // Remove GIF
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) || strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 7' ) ) {
$type='png';
}
else {
$type='svg';
}
return 'http://domain.com/images/smilies/'.$img.$type.'';
}
/**
* Filter smilies to allow PNG format
* @license http://www.gnu.org/licenses/gpl-3.0.html
* @since 1.0.0
*/
add_filter('smilies_src','my_png_smilies_src', 1, 10);
function my_png_smilies_src($img_src, $img, $siteurl){
$img = rtrim($img, "gif");
return $siteurl.'/images/smilies/'.$img.'png';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment