Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working remotely since 1999

Ihor Vorotnov ihorvorotnov

🏠
Working remotely since 1999
View GitHub Profile
View wordpress-transient-caching.php
<?php
/**
* Setup wp_query arguments for the loop. Cache the results for 4 hours.
*
* @link http://codex.wordpress.org/Transients_API
*/
// Check for transient
if ( ! ( $my_query = get_transient( 'foo_featured_posts' ) ) ) {
@ihorvorotnov
ihorvorotnov / rgba-bg
Created Feb 20, 2014
Cross-browser semi-transparent backgrounds using RGBA and IE filter
View rgba-bg
/**
* Cross-browser solution for semi-transparent backgrounds using RGBA.
* Read more: http://hammerspace.co.uk/2011/10/cross-browser-alpha-transparent-background-css
*
* Note: in IE ARGB AA is a HEX value, not a floating point.
* Note: there is some info that IE turns off ClearType with filters.
*
* 2Do: explore solution for semi-transparent foregrounds.
* 2Do: convert to SASS mixin.
*/
@ihorvorotnov
ihorvorotnov / SASS-Build
Last active Aug 29, 2015
SASS/SCSS build command for Sublime Text to always compile only one main style.scss
View SASS-Build
/**
* Stop SASS Build package from compiling _chunks and always compile one style.scss which @imports all _chunks
* /scss/style.scss => /style.css
* Based on http://hovercraftie.tumblr.com/post/61592756918/update-sass-build-plug-in-for-sublime-text-2-to-allow
*/
// Put this in SASS.sublime-build
"cmd": ["sass", "--update", "${file_path}/style.scss:${file_path}/../style.css", "--stop-on-error", "--no-cache"],
// Put this is SASS - Compressed.sublime-build
@ihorvorotnov
ihorvorotnov / human-date
Created Feb 20, 2014
Display time in how long ago format (WordPress)
View human-date
human_time_diff( $from, $to );
echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';
@ihorvorotnov
ihorvorotnov / js-detect-mobile
Created Feb 20, 2014
Detect Mobile with Javascript
View js-detect-mobile
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
@ihorvorotnov
ihorvorotnov / gradient-bg
Created Feb 20, 2014
Full Page Gradient Background
View gradient-bg
html {
background: #red; /* fallback color */
background: linear-gradient( to bottom, #red, #blue);
background-repeat: no-repeat;
background-size: cover;
width: 100%;
height: 100%;
}
@ihorvorotnov
ihorvorotnov / wp-hard-crop
Created Feb 21, 2014
Force hard crop for WordPress uploaded images
View wp-hard-crop
// Standard Size Thumbnail
if(false === get_option("thumbnail_crop")) {
add_option("thumbnail_crop", "1");
} else {
update_option("thumbnail_crop", "1");
}
// Medium Size Thumbnail
if(false === get_option("medium_crop")) {
add_option("medium_crop", "1");
@ihorvorotnov
ihorvorotnov / wp-sharedcount
Last active Oct 28, 2017
WordPress - count shares via Sharedcount.com
View wp-sharedcount
/**
* http://www.sharedcount.com/documentation.php
*/
function social_shares() {
$url = get_permalink( $post_id );
$json = file_get_contents("http://api.sharedcount.com/?url=" . rawurlencode($url));
$counts = json_decode($json, true);
$totalcounts= array(
"twitter" => $counts["Twitter"],
"facebook" => $counts["Facebook"]["total_count"],
@ihorvorotnov
ihorvorotnov / get-social-shares
Last active Oct 20, 2020
Get number of shares from social platforms
View get-social-shares
Facebook*:
https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json
+ works, returns shares, likes, comments and total
Twitter:
http://urls.api.twitter.com/1/urls/count.json?url=%%URL%%&callback=twttr.receiveCount
+ v1 API but still works
Reddit:
http://buttons.reddit.com/button_info.json?url=%%URL%%
@ihorvorotnov
ihorvorotnov / wp-get-content
Created Feb 21, 2014
WordPress: get post content by ID
View wp-get-content
/**
* You often need to get the content or title from a specific post.
* Sometimes, using a custom loop is the better option, but when you only need
* to get information from a specific post, there’s a better option
*/
echo get_post_field('post_content', $post_id);