Skip to content

Instantly share code, notes, and snippets.

function igb_truncator( $string, $chars = 50 ) {
$string = strip_tags( $string );
if ( $chars < strlen( $string ) ) {
$string = mb_substr( $string, 0, strpos( wordwrap( $string, $chars ), "\n" ) );
$string = $string . '...';
}
return $string;
@vancoder
vancoder / get-ordinal
Last active December 29, 2015 14:29
Function to return an ordinal of the integer passed as an argument.
function get_ordinal( $number ) {
$suffix = array( 'th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th' );
if ( ($number % 100) >= 11 && ($number % 100) <= 13 )
$ordinal = $number . 'th';
else
$ordinal = $number . $suffix[$number % 10];
return $ordinal;
}
@vancoder
vancoder / is-ajax
Created November 26, 2013 22:45
Custom Ajax conditional. jQuery requests will not trigger the DOING_AJAX constant.
function is_ajax() {
if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) &&
!empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) &&
strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) {
return true;
}
return false;
}