Skip to content

Instantly share code, notes, and snippets.

View yellowberri-snippets's full-sized avatar

Dalton Yellowberri yellowberri-snippets

View GitHub Profile
@yellowberri-snippets
yellowberri-snippets / PHP: WP: Check if User is Role
Created January 10, 2014 16:29
PHP: WP: Check if User is Role
function user_is_role($role) {
$userId = get_current_user_id();
$userData = get_userdata($userId);
return isset($userData->caps[$role]);
}
@yellowberri-snippets
yellowberri-snippets / PHP: WP: Custom Menu Icons WP 3.8+
Last active January 3, 2016 03:29
PHP: WP: Custom Menu Icons WP 3.8+
function custom_admin_icons() {
// Change CSS selector to menu name.
// Change content property to new icon code.
// Icons found here: http://melchoyce.github.io/dashicons/
echo '
<style>
#adminmenu #menu-posts-CPT div.wp-menu-image:before { content: "\f161"; }
</style>
';
@yellowberri-snippets
yellowberri-snippets / SASS: Sprite Icon Classes with Tooltip
Created January 13, 2014 17:52
SASS: Sprite Icon Classes with Tooltip
.social-icon {
position:relative;
display:block;
opacity:0.8;
@include transition(opacity $trans-speed $trans-ease);
&:hover {
opacity: 1;
}
@yellowberri-snippets
yellowberri-snippets / JS: Lazy Load Background Images
Last active August 29, 2015 13:55
JS: Lazy Load Background Images
// Requires imagesLoaded.js
// https://github.com/desandro/imagesloaded
$('html').imagesLoaded( function() {
var mobileWidth = 600;
var i = 0;
var selector = '';
var bgUrl = '';
if ( $(window).width() > mobileWidth ) {
@include fontFace ("Property Name", "font-folder/filename-without-ext");
@yellowberri-snippets
yellowberri-snippets / PHP: WP: Custom Excerpt Lengths
Last active August 29, 2015 13:56
PHP: WP: Custom Excerpt Lengths
// Custom Excerpt Limits
// http://www.wpexplorer.com/custom-excerpt-lengths-wordpress/
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
@yellowberri-snippets
yellowberri-snippets / SASS: Animation Delay For Loop
Last active March 14, 2017 15:26
SASS: Animation Delay For Loop
li {
@for $i from 1 through 30 {
&:nth-of-type(#{$i}) {
@include transition-delay(#{$i * 100}ms);
}
}
}
@yellowberri-snippets
yellowberri-snippets / JS: Haversine Formula Distance Between Lat,Lng Points in Km
Last active April 10, 2020 02:05
JS: Haversine Formula Distance Between Lat,Lng Points in Km
function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1); // deg2rad below
var dLon = deg2rad(lon2-lon1);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // Distance in km
return d;
}
@yellowberri-snippets
yellowberri-snippets / PHP: WP: Access $wp_query Page Query Vars
Created February 21, 2014 16:06
PHP: WP: Print $wp_query Page Query Vars
print_r( $wp_query->query_vars );
@yellowberri-snippets
yellowberri-snippets / SASS: Quick Columns Mixin
Created February 24, 2014 16:14
SASS: Quick Columns Mixin
@mixin left-col($width: '68%') {
float:left;
width:#{$width};
@include clearfix;
@include breakpoint(narrowColumn) {
float:none;
width:100%;
}
}