Skip to content

Instantly share code, notes, and snippets.

@artboard-studio
Last active August 9, 2017 09:16
Show Gist options
  • Save artboard-studio/efa7a7bdd09b4ebf57be to your computer and use it in GitHub Desktop.
Save artboard-studio/efa7a7bdd09b4ebf57be to your computer and use it in GitHub Desktop.
Initials Thumbnail for WordPress
// Capital Framework Initials Thumbnail
.cfw-initails-thumbnail {
background: #d8d8d8;
color: #333;
width: 45px;
height: 45px;
display: inline-block;
border-radius: 50%;
margin-right: 15px;
text-align: center;
line-height: 45px;
font-size: 16px;
text-transform: uppercase;
font-weight: 300;
}
<?php
/**
* Takes a string and gets the initials of the first two words and puts them in a span
* @param string|$the_title_string The text from wich the initials will be taken
* @return The initials in a span with a class of .cfw-initails-thumbnail
*/
function cfw_initails_thumbnail($the_title_string, $initials_limit) {
$cfw_thumb_initials = preg_split("/[\s,_-]+/", $the_title_string, $initials_limit );
$the_initial = "";
foreach ( $cfw_thumb_initials as $w ) {
$the_initial .= $w[0];
}
return '<span class="cfw-initails-thumbnail">'.$the_initial.'</span>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment