Skip to content

Instantly share code, notes, and snippets.

View ihorduchenko's full-sized avatar
💭
Working

Ihor Duchenko ihorduchenko

💭
Working
View GitHub Profile
@ihorduchenko
ihorduchenko / loadIOSStyles.js
Created September 9, 2017 19:52
Load styles if IOS
var isMobile = (/iPhone|iPad|iPod/i.test(navigator.userAgent));
if (!isMobile) {
(function() {
var css = [
'./path/to/file.css'
],
i = 0,
link = document.createElement('link'),
head = document.getElementsByTagName('head')[0],
tmp;
@ihorduchenko
ihorduchenko / highlight_search_result.php
Created September 12, 2017 13:03
Highlight search results in Wordpress search
function highlight_results($text){
if(is_search()){
$keys = implode('|', explode(' ', get_search_query()));
$text = preg_replace('/(' . $keys .')/iu', '<span class="search-highlight">\0</span>', $text);
}
return $text;
}
add_filter('the_content', 'highlight_results');
add_filter('the_excerpt', 'highlight_results');
add_filter('the_title', 'highlight_results');
@ihorduchenko
ihorduchenko / swipers.js
Created September 27, 2017 09:46
Swiper: 2 synchronous sliders with different speed
var homeBannerTitleSwiper = new Swiper('.home-banner_title-slider', {
pagination: '.home-banner_slider-pagination',
paginationClickable: true,
prevButton: '.home-banner_slider-prev',
nextButton: '.home-banner_slider-next',
speed: 750,
slidesPerView: 1,
spaceBetween: 15,
loop: true,
onlyExternal:true
@ihorduchenko
ihorduchenko / each.js
Last active October 6, 2017 08:58
Playing with $(this) and .each (jQuery) | Contact Form 7: Delete file from input[type="file"]
(function ($) {
$('.wpcf7-file').each(function() {
$(this).change(function() {
var file = $(this)[0].files[0];
console.log(file);
if (file) {
console.log("Not empty");
$(this).parents("p").siblings(".delete-file").show();
$(this).parents("p").siblings(".file-name").show().html(file.name);
}
@ihorduchenko
ihorduchenko / sudo
Created October 17, 2017 09:34
Ubuntu 16.04 setting permissions to 777 for www folder
sudo chown -Rf www-data.www-data /var/www/html/
sudo chmod 777 -R /var/www/html
@ihorduchenko
ihorduchenko / pagination.php
Created October 19, 2017 14:11
Creating pagination on custom templates
<section class="news-list" data-aos-offset="0" data-aos-delay="2500"
data-aos="fade" data-aos-duration="1500">
<div class="news-list-mixer">
<?php
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$query_args = array(
'post_type' => 'news',
'order' => 'DESC',
'paged' => $paged,
@ihorduchenko
ihorduchenko / wp_query.php
Created October 25, 2017 08:39
WP_Query of related posts by array of categories of current post
$cats = wp_get_post_terms( get_the_ID(), 'category' );
$cats_ids = array();
foreach( $cats as $wpex_related_cat ) {
$cats_ids[] = $wpex_related_cat->term_id;
}
$args = array(
'post_type' => 'post',
'order' => 'ASC',
'posts_per_page' => '3',
'category__in' => $cats_ids,
@ihorduchenko
ihorduchenko / plugins.wp-config.php
Created October 31, 2017 07:00
Allow wordpress to install plugins on local machine
//Insert in wp-config.php file
define('FS_METHOD','direct');define('FS_CHMOD_DIR',0755);define('FS_CHMOD_FILE',0644);
define('WP_TEMP_DIR',dirname(__FILE__).'/wp-content/uploads');
@ihorduchenko
ihorduchenko / simple-validation.js
Created November 7, 2017 09:26
Disable submit button while filling form fields
$(document).ready(function () {
$('.submit-btn').prop('disabled', true);
$('.form-field').keyup(function () {
$('.form-field').each(function () {
$('.submit-btn').prop('disabled', this.value == "" ? true : false);
@ihorduchenko
ihorduchenko / kia_add_script_to_footer.php
Created November 9, 2017 08:27 — forked from helgatheviking/kia_add_script_to_footer.php
Add plus and minus buttons to WooCommerce quantity inputs