Skip to content

Instantly share code, notes, and snippets.

View ihorvorotnov's full-sized avatar
🇺🇦
Working remotely since 1999

Ihor Vorotnov ihorvorotnov

🇺🇦
Working remotely since 1999
View GitHub Profile
@ihorvorotnov
ihorvorotnov / mobile_tablet.php
Created May 8, 2015 15:34
Custom function to separate phones and tablets with wp_is_mobile() function
<?php
/**
* It's just an example, proof of concept.
* You should modify it to include more tablets, not only iPad.
*/
function my_wp_is_mobile() {
static $is_mobile;
if ( isset($is_mobile) )
@ihorvorotnov
ihorvorotnov / script.js
Last active August 28, 2022 11:08
Using wp_is_mobile() in WordPress to detect mobile users (phones and tablets)
jQuery( document ).ready( function($) {
if ( $( "body" ).hasClass("wp-is-mobile"){
/* Do javascript for mobile */
}
else{
/* Do javascript for non-mobile */
}
});
@ihorvorotnov
ihorvorotnov / LocalValetDriver.php
Created October 24, 2020 16:17 — forked from mishterk/LocalValetDriver.php
A local Valet driver for proxying images to a remote host
<?php
/**
* Class LocalValetDriver
*
* This class demonstrates how we might go about proxying any missing local images to a remote host. i.e; the production
* site. This has been created with WordPress in mind but could be adjusted to work with any other system.
*/
class LocalValetDriver extends WordPressValetDriver {
@ihorvorotnov
ihorvorotnov / wp-reposive-video
Created March 7, 2014 17:04
WordPress Resposive Videos (oEmbed + iframe/embed)
1. Add this to your functions.php or inc/templates-tags.php
/**
* Wrap videos embedded via oEmbed to make them responsive
*/
function p2_wrap_oembed( $html, $url, $attr, $post_id ) {
return '<div class="video-embed">' . $html . '</div>';
}
add_filter( 'embed_oembed_html', 'p2_wrap_oembed', 99, 4 );
@ihorvorotnov
ihorvorotnov / functions.php
Last active March 17, 2021 10:01
Painless 3rd party marketing scripts in WordPress
<?php
// Enqueue all js codes combined in a single file.
function enqueue_theme_assets()
{
wp_enqueue_script(
'trackers',
get_stylesheet_directory_uri() . '/js/trackers.js',
null,
null,
<?php
# Check: https://onexa.nl/wordpress/toolbar-link-redis-object-cache/
/**
* Add a link to the Admin Toolbar to easily flush the Redis cache (Redis Object Cache plugin)
*
* @author Hiranthi Herlaar, onexa.nl
* @version 2.0
*
@ihorvorotnov
ihorvorotnov / get-social-shares
Last active October 20, 2020 12:15
Get number of shares from social platforms
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%%
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@ihorvorotnov
ihorvorotnov / functions.php
Created August 7, 2020 11:55
Custom wrapper for require() instead of get_template_part()
<?php
define( 'THEME_PATH', __DIR__ );
/**
* A faster alternative to native get_template_part() function.
*
* @param string $template
* @param mixed $data
*
* @return void
@ihorvorotnov
ihorvorotnov / publickey-git-error.markdown
Created October 3, 2015 01:31 — forked from adamjohnson/publickey-git-error.markdown
Fix "Permission denied (publickey)" error when pushing with Git

"Help, I keep getting a 'Permission Denied (publickey)' error when I push!"

This means, on your local machine, you haven't made any SSH keys. Not to worry. Here's how to fix:

  1. Open git bash (Use the Windows search. To find it, type "git bash") or the Mac Terminal. Pro Tip: You can use any *nix based command prompt (but not the default Windows Command Prompt!)
  2. Type cd ~/.ssh. This will take you to the root directory for Git (Likely C:\Users\[YOUR-USER-NAME]\.ssh\ on Windows)
  3. Within the .ssh folder, there should be these two files: id_rsa and id_rsa.pub. These are the files that tell your computer how to communicate with GitHub, BitBucket, or any other Git based service. Type ls to see a directory listing. If those two files don't show up, proceed to the next step. NOTE: Your SSH keys must be named id_rsa and id_rsa.pub in order for Git, GitHub, and BitBucket to recognize them by default.
  4. To create the SSH keys, type ssh-keygen -t rsa -C "your_email@example.com". Th