Skip to content

Instantly share code, notes, and snippets.

View tux255's full-sized avatar

Andrii Haranin tux255

  • Kyiv
  • 18:16 (UTC -12:00)
View GitHub Profile
@tux255
tux255 / ajax_uploadfile.js
Last active August 1, 2021 13:54
AJAX Upload file. Wordpress
jQuery(document).on('click', '.save-support', function (e) {
var supporttitle = jQuery('.support-title').val();
var querytype = jQuery('.support-query').val();
var file_data = jQuery('#sortpicture').prop('files')[0];
var form_data = new FormData();
if (supporttitle == '') {
jQuery('.support-title').css({"border": "1px solid red"})
@tux255
tux255 / disable-emoji-wordpress.php
Created September 30, 2020 12:57 — forked from JeroenSormani/disable-emoji-wordpress.php
Emoji disabling code snippet for WordPress
<?php // For implementation instructions see: https://aceplugins.com/how-to-add-a-code-snippet/
/**
* Disable WP 4.2 emoji
*/
function ace_remove_emoji() {
add_filter( 'emoji_svg_url', '__return_false' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
@tux255
tux255 / index.html
Created April 1, 2020 06:01
JS Bin text gradient css // source https://jsbin.com/qazutol
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="text gradient css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
h1 {
font-size: 72px;
@tux255
tux255 / console.commands
Last active November 25, 2019 06:26
Clear docker containers. Used to fix: Docker-compose up failing because "port is already allocated"
docker-compose down
docker rm -fv $(docker ps -aq)
sudo lsof -i -P -n | grep {PORT}
@tux255
tux255 / functions.php
Last active October 18, 2019 08:37
Loadspeed theme improvements for Wordpress -> functions.php
// Remove query strings from urls
function remove_query_strings( $src ) {
$src = remove_query_arg( array( 'v', 'ver', 'rev', 'bg_color', 'sensor' ), $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_query_strings', 10, 2 );
add_filter( 'script_loader_src', 'remove_query_strings', 10, 2 );
// Defer parsing of JavaScripts
@tux255
tux255 / query
Created February 22, 2019 09:20
Wordpress links replacer
UPDATE ac_options SET option_value = replace(option_value, 'http://to.replace', 'http://placehold.er') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE ac_posts SET guid = replace(guid, 'http://to.replace','http://placehold.er');
UPDATE ac_posts SET post_content = replace(post_content, 'http://to.replace', 'http://placehold.er');
UPDATE ac_postmeta SET meta_value = replace(meta_value,'http://to.replace','http://placehold.er');
@tux255
tux255 / sitemap_generator_cached.php
Created September 4, 2018 09:17
sitemap_generator_cached
<?php
header("Content-type: text/xml");
$cache_time = 3600 * 24; // Time in seconds to keep a page cached
$cache_folder = '/'; // Folder to store cached files (no trailing slash)
$cache_filename = $cache_folder.md5($_SERVER['REQUEST_URI']); // Location to lookup or store cached file
//Check to see if this file has already been cached
// If it has get and store the file creation time
$cache_created = (file_exists($cache_filename)) ? filemtime($cache_filename) : 0;
@tux255
tux255 / wpcf7-w3tc-fix-ajax.php
Created October 4, 2016 11:46
Hack Contact Form 7 to avoid unwanted ajax calls
// Hack Contact Form 7 to avoid unwanted ajax calls
// see http://stackoverflow.com/questions/19632244/is-w3-total-cache-compatible-with-contact-form-7
add_action('wpcf7_enqueue_scripts', 'hack_cf7');
function hack_cf7() {
$_wpcf7 = array(
'loaderUrl' => wpcf7_ajax_loader(),
'sending' => __( 'Sending ...', 'contact-form-7' )
);
wp_localize_script( 'contact-form-7', '_wpcf7', $_wpcf7 );
}
@tux255
tux255 / gist:afe9331cf64b06adfcaa3a4fc67805d9
Created May 7, 2018 11:55 — forked from perusio/gist:1326701
Mobile device detection in Nginx with just 7 lines of configuration
### Testing if the client is a mobile or a desktop.
### The selection is based on the usual UA strings for desktop browsers.
## Testing a user agent using a method that reverts the logic of the
## UA detection. Inspired by notnotmobile.appspot.com.
map $http_user_agent $is_desktop {
default 0;
~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule
~*spider|crawl|slurp|bot 1; # bots
~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes
@tux255
tux255 / Sitemap.xml
Created May 7, 2018 11:42 — forked from misterebs/Sitemap.xml
Create sitemap.xml for wordpress site without plugins
Copy this code to function.php
//Sitemap XML
/*
function to create sitemap.xml file in root directory of site
*/