Skip to content

Instantly share code, notes, and snippets.

View sergeliatko's full-sized avatar
💭
Looking for talented PHP / JavaScript / WordPress developers. Apply now!

Serge Liatko sergeliatko

💭
Looking for talented PHP / JavaScript / WordPress developers. Apply now!
View GitHub Profile
@sergeliatko
sergeliatko / functions.php
Last active November 9, 2016 11:31
Load child theme text domain in Genesis using a filter
/* LOAD TEXT DOMAIN */
load_child_theme_textdomain(
'sergeliatko',
apply_filters(
'child_theme_textdomain',
get_stylesheet_directory() . '/languages',
'sergeliatko'
)
);
@sergeliatko
sergeliatko / wp_parse_args_recursive.php
Last active November 27, 2016 13:26
Parses arguments considering multi-dimensional arrays and objects
<?php
if( ! function_exists('wp_parse_args_recursive') ) {
/**
* Parses arguments considering multi-dimensional arrays and objects.
*
* @param mixed $args
* @param mixed $default
* @param bool $preserve_integer_keys
*
* @return mixed
@sergeliatko
sergeliatko / save-post-meta.php
Last active January 26, 2017 09:08
Saves post meta in WordPress
<?php
/** add save_post_meta to save_post hook */
add_action( 'save_post', 'save_post_meta', 10, 3 );
/**
* Saves post meta.
*
* @param $post_ID
* @param WP_Post $post
* @param $update
*
@sergeliatko
sergeliatko / PostImageSize.php
Created January 29, 2017 12:12
Adds image size to WordPress with setting to control the dimensions in media.php screen and size name in WP user interface.
<?php
/**
* Adds image size to WordPress with setting to control the dimensions in media.php screen and size name in WP user interface.
* example:
*
* if( !defined('PIS_TXD') ) {
* define( 'PIS_TXD', 'your-text-domain' );
* }
* require_once( dirname( __FILE__ ) . '/PostImageSize.php' );
* $teaser_size = new PostImageSize( 'teaser', __( 'Teaser', 'your-text-domain' ), 460, 280, true );
@sergeliatko
sergeliatko / get_terms_by_common_posts.php
Created May 29, 2017 19:53
Returns terms from a different taxonomy using common published posts as search criteria. (Ex: get post tags assigned to all posts in a specific category)
<?php
/**
* Returns terms from a different taxonomy using common published posts as search criteria.
* Example: get list of post tags assigned to all posts in a specific category.
*
* @param array $ids Array of source term ids.
* @param string $source Source taxonomy.
* @param string $target Target taxonomy.
*
* @return array
@sergeliatko
sergeliatko / track-phone-link-clicks.html
Last active October 8, 2018 16:46
Html code (plain javascript) that allows tracking of phone number clicks within Google Analytics
@sergeliatko
sergeliatko / style.css
Created July 8, 2017 18:07
Add phone icon to clickable phone numbers in WordPress with dashicons
/* clickable phone numbers */
a[href^="tel:"]:before
{
content: "\f525";
font-family: 'dashicons';
vertical-align: middle;
margin-right: 0.25em;
opacity: 0.65;
}
@sergeliatko
sergeliatko / removeValue.js
Last active August 23, 2017 18:00
Removes value from an array
function removeValue( v, a ) {
if( a.length ) {
var i = a.indexOf(v);
if( -1 === i ) {
return a;
}
a.splice( i, 1 );
return removeValue( v, a );
}
return a;
@sergeliatko
sergeliatko / cc-mask.php
Last active October 3, 2017 10:01
PHP funtion to mask credit card number
<?php
/**
* Masks credit card number leaving up to 4 last available digits.
*
* @param string $n Credit card number (up to 16 characters)
* @param string $m Masking string
* @param int $v Maximum number of visible characters at the end of the credit card number (in range of 0-4)
*
* @return string
*/
@sergeliatko
sergeliatko / functions.php
Last active October 30, 2017 10:18
How to add inline styles to theme stylesheet in WordPress
<?php
/**
* Adds extra CSS rules to the HEAD html tag after to your theme stylesheet.
*/
function my_extra_css() {
wp_add_inline_style(
sanitize_title_with_dashes( wp_get_theme()->get( 'Name' ) ),
'/*** YOUR CSS HERE ***/'
);
}