Skip to content

Instantly share code, notes, and snippets.

@nestoralvaro
nestoralvaro / konamiCode.js
Created January 11, 2012 22:30
Snippet to detect Konami Code (and then do something)
/******************************************************************************
* This script detects the Konami code
* (Full Konami Code obtained from: http://en.wikipedia.org/wiki/Konami_Code)
* If the Konami code is detected the function called "startUpKonami" is invoked.
* You can do whatever you want on "startUpKonami". Right now this method just:
* - Detachs the Konami code detection (so no further detections can happen).
* - Invokes an external function.
*
* Note: In case the user presses keys like "shift", "caps lock", "Ctrl"...
* the code will have to be reentered from scratch
@thegdshop
thegdshop / gist:3197540
Created July 29, 2012 10:52
WooCommerce - Add category body class in single product view
<?php
// add taxoonomy term to body_class
function woo_custom_taxonomy_in_body_class( $classes ){
if( is_singular( 'product' ) )
{
$custom_terms = get_the_terms(0, 'product_cat');
if ($custom_terms) {
foreach ($custom_terms as $custom_term) {
$classes[] = 'product_cat_' . $custom_term->slug;
@ashhitch
ashhitch / update-urls.sql
Last active September 5, 2022 11:22
Update your site URL in Wordpress to a new one. If you have changed your table prefix from wp_ the update the code below first.
/* update all post permalinks */
update wp_posts
set guid = REPLACE(guid, 'http://www.oldsite.com', 'http://www.newsite.com')
where guid LIKE '%http://www.oldsite.com%';
/* update all post content */
update wp_posts
SET post_content = REPLACE(post_content, 'http://www.oldsite.com', 'http://www.newsite.com')
where post_content LIKE '%http://www.oldsite.com%';
@raucao
raucao / typekit.js
Last active February 12, 2020 06:25
Improved Typekit embed code
(function(d) {
var tkTimeout=3000;
if(window.sessionStorage){if(sessionStorage.getItem('useTypekit')==='false'){tkTimeout=0;}}
var config = {
kitId: 'a1b2c3f4',
scriptTimeout: tkTimeout
},
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";if(window.sessionStorage){sessionStorage.setItem("useTypekit","false")}},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='//use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
})(document);
@w0rm
w0rm / svgstore.html
Created August 6, 2014 15:26
Load combined svg file into body
<html>
<body>
<!-- load combined svg file (with symbols) into body-->
<script>
(function (doc) {
var scripts = doc.getElementsByTagName('script')
var script = scripts[scripts.length - 1]
var xhr = new XMLHttpRequest()
xhr.onload = function () {
@thetrickster
thetrickster / cf7-us-state-dropdown-code.txt
Last active August 29, 2015 14:05
Contact Form 7 (CF7) US State Dropdown with piping-- Shows full State name to user but passes only state abbreviation to form. Allows for more accurate state capture by removing abbreviations for frontend user and using select removes typos.
[select state include_blank "Alabama|AL" "Alaska|AK" "Arizona|AZ" "Arkansas|AR" "California|CA" "Colorado|CO" "Connecticut|CT" "Delaware|DE" "Florida|FL" "Georgia|GA" "Hawaii|HI" "Idaho|ID" "Illinois|IL" "Indiana|IN" "Iowa|IA" "Kansas|KS" "Kentucky|KY" "Louisiana|LA" "Maine|ME" "Maryland|MD" "Massachusetts|MA" "Michigan|MI" "Minnesota|MN" "Mississippi|MS" "Missouri|MO" "Montana|MT" "Nebraska|NE" "Nevada|NV" "New Hampshire|NH" "New Jersey|NJ" "New Mexico|NM" "New York|NY" "North Carolina|NC" "North Dakota|ND" "Ohio|OH" "Oklahoma|OK" "Oregon|OR" "Pennsylvania|PA" "Rhode Island|RI" "South Carolina|SC" "South Dakota|SD" "Tennessee|TN" "Texas|TX" "Utah|UT" "Vermont|VT" "Virginia|VA" "Washington|WA" "West Virginia|WV" "Wisconsin|WI" "Wyoming|WY"]
@westonruter
westonruter / force_balance_tags2.php
Last active August 21, 2019 08:44
Use DOMDocument to do a more robust job at force_balance_tags.
<?php
/**
* Use DOMDocument to do a more robust job at force_balance_tags.
*
* "force_balance_tags() is not a really safe function. It doesn’t use an HTML parser
* but a bunch of potentially expensive regular expressions. You should use it only if
* you control the length of the excerpt too. Otherwise you could run into memory issues
* or some obscure bugs." <http://wordpress.stackexchange.com/a/89169/8521>
*
@bmoredrew
bmoredrew / gist:c32ef178f138c8335ca2
Created March 3, 2015 18:40
Add service fee to woo cart per item
add_action( 'woocommerce_cart_calculate_fees', 'df_add_handling_fee' );
function df_add_handling_fee( $cart_object ) {
global $woocommerce;
// $specialfeecat = 3711; // category id for the special fee
$spfee = 0.00; // initialize special fee
$spfeeperprod = 2.50; //special fee per product
//Getting Cart Contents.
$cart = $woocommerce->cart->get_cart();
@thetrickster
thetrickster / cf7-custom-validations.md
Last active August 29, 2015 14:18
Contact Form 7 4.1 Custom Validations Fix/Error
@bmoredrew
bmoredrew / gist:dcc7d04b23e785f6c0bb
Created April 27, 2015 15:56
Front-end Attendee List WooCommerce WooTickets Events Calendar Plugin
<?php
global $current_user;
get_currentuserinfo();
if (is_user_logged_in() && $current_user->ID == $post->post_author) {
// Build a list of attendees
$attendeeList = TribeEventsTickets::get_event_attendees($event_id);
$customerList = array();