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 / wordpress.htaccess
Last active March 18, 2021 18:00
.htaccess snippets for WordPress site
<IfModule mod_headers.c>
<FilesMatch "\.(txt|xml|js)$">
Header set Cache-Control "max-age=31536000"
</FilesMatch>
<FilesMatch "\.(css)$">
Header set Cache-Control "max-age=31536000"
</FilesMatch>
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)$">
@ihorduchenko
ihorduchenko / cf-7-cookies-sumbissions.js
Created February 6, 2019 12:18
Prevent equal multiple Contact Form 7 submissions using cookies
var Cookie = {
Set: function (name, value) {
var expires = "";
var date = new Date();
date.setTime(date.getTime() + (5 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + value + expires + "; path=/";
},
Get: function (name) {
var nameEQ = name + "=";
@ihorduchenko
ihorduchenko / cookies-1.js
Last active February 6, 2019 12:26
Prevent equal multiple Contact Form 7 submissions using cookies (part 1)
var Cookie = {
Set: function (name, value) {
var expires = "";
var date = new Date();
date.setTime(date.getTime() + (5 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + value + expires + "; path=/";
},
Get: function (name) {
var nameEQ = name + "=";
@ihorduchenko
ihorduchenko / cookies-2.js
Created February 6, 2019 12:25
Prevent equal multiple Contact Form 7 submissions using cookies (part 2)
document.addEventListener("DOMContentLoaded", function() {
// Getting cookies
var cookie_name = Cookie.Get("form_name");
var cookie_email = Cookie.Get("form_email");
var cookie_phone = Cookie.Get("form_phone");
// Checking if exist
var isNameSet = cookie_name != null;
var isEmailSet = cookie_email != null;
var isPhoneSet = cookie_phone != null;
@ihorduchenko
ihorduchenko / disable_comments_functions.php
Created April 10, 2019 06:31
Disable comments functionality on WordPress
// Totally disable comments functionality
function lp_disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
if ( post_type_supports( $post_type, 'comments' ) ) {
remove_post_type_support( $post_type, 'comments' );
remove_post_type_support( $post_type, 'trackbacks' );
}
}
}
@ihorduchenko
ihorduchenko / .gitignore.wordpress
Created May 21, 2019 06:58
.gitignore for WordPress (place it in the root directory)
# -----------------------------------------------------------------
# .gitignore for WordPress
# Bare Minimum Git
# http://ironco.de/bare-minimum-git/
# ver 20150227
#
# This file is tailored for a WordPress project
# using the default directory structure
#
# This file specifies intentionally untracked files to ignore
@ihorduchenko
ihorduchenko / functions.php
Created September 6, 2019 14:22
Load certain post clicking on link using Ajax
// Ajaxify loading resources
function ajax_load_cases(){
$al_id = $_POST['id'];
$al_type = $_POST['type'];
$al_args = array(
'p' => $al_id,
'post_type' => $al_type,
'posts_per_page' => -1
);
$al_query = new WP_Query( $al_args ); ?>
@ihorduchenko
ihorduchenko / functions.php
Created November 1, 2019 07:36
Add list of countries as taxonomy using functions.php snippet
add_action('init', 'add_countries', 100);
function add_countries() {
$country_array = array(
$countries = array(
"AF" => "Afghanistan",
"AL" => "Albania",
"DZ" => "Algeria",
"AS" => "American Samoa",
"AD" => "Andorra",
@ihorduchenko
ihorduchenko / desc.php
Created April 16, 2020 11:40 — forked from igorbenic/desc.php
How to Programmatically Change Yoast SEO Open Graph Meta | http://www.ibenic.com/programmatically-change-yoast-seo-open-graph-meta
<?php
function change_yoast_seo_og_meta() {
add_filter( 'wpseo_opengraph_desc', 'change_desc' );
}
function change_desc( $desc ) {
// This article is actually a landing page for an eBook
if( is_singular( 123 ) ) {
@ihorduchenko
ihorduchenko / woocommerce-tagmanager-thankyou-page-code.php
Last active July 5, 2020 14:49
Woocommerce: Tag Manager - Thankyou page tracking code
<?php if (is_order_received_page()) {
$order_id = wc_get_order_id_by_order_key( $_GET['key'] );
$order = wc_get_order( $order_id );
$cookie_name = "order_data_sent";
$cookie_value = $order_id;
$transaction_id = ($order->transaction_id ? $order->transaction_id : $order_id);
$total = $order->total;
$total_tax = $order->total_tax;
$shipping_method = @array_shift($order->get_shipping_methods());