Skip to content

Instantly share code, notes, and snippets.

var animatedHeader = (function() {
var docElem = document.documentElement,
header = document.querySelector( '.site-header' ),
didScroll = false,
changeHeaderOn = 1;
function init() {
window.addEventListener( 'scroll', function( event ) {
if( !didScroll ) {
@dannyconnolly
dannyconnolly / jquery element class loop
Created December 14, 2013 12:21
Simple jquery loop for looping through elements and changing class
function gvi_slider(el, t, c) {
var $slides = $(el);
(function _loop(idx) {
$slides.removeClass(c).eq(idx).addClass(c);
setTimeout(function () {
_loop((idx + 1) % $slides.length);
}, t);
}(0));
}
@dannyconnolly
dannyconnolly / Is blog
Created December 2, 2013 15:50
Check if main blog page is used in wordpress
function is_blog() {
global $post;
//Post type must be 'post'.
$post_type = get_post_type($post);
//Check all blog-related conditional tags, as well as the current post type,
//to determine if we're viewing a blog page.
return (
/**
* Process meta
*
* Processes the custom tab options when a post is saved
*/
function process_product_meta_custom_tab($post_id) {
update_post_meta($post_id, 'custom_tab_enabled', (isset ($_POST['custom_tab_enabled']) && $_POST['custom_tab_enabled']) ? 'yes' : 'no');
update_post_meta($post_id, 'custom_tab_title', $_POST['custom_tab_title']);
update_post_meta($post_id, 'custom_tab_content', $_POST['custom_tab_content']);
}
@dannyconnolly
dannyconnolly / gist:7673502
Last active December 29, 2015 12:49
Child Menu for Wordpress
<?php
global $wp_query;
if( empty($wp_query->post->post_parent) ) {
$parent = $wp_query->post->ID;
} else {
$parent = array_reverse(get_post_ancestors($post->ID));
$parent = $parent[0];
}
if(wp_list_pages("title_li=&child_of=$parent&echo=0" )) {
?>
@dannyconnolly
dannyconnolly / media-taxonomies.php
Created November 2, 2015 08:55
Add taxonomies to worpress media attachments
/**
* add categories for attachments
*/
function add_categories_for_attachments() {
register_taxonomy_for_object_type('category', 'attachment');
}
add_action('init', 'add_categories_for_attachments');
@dannyconnolly
dannyconnolly / Add custom field to woocommerce checkout.
Created June 17, 2015 09:52
Add custom field to woocommerce checkout.
/**
* Add vehicle registration field to the checkout page
*/
add_action( 'woocommerce_after_order_notes', 'car_registration_checkout_field' );
function car_registration_checkout_field( $checkout ) {
echo '<div id="car_registration_checkout_field"><h2>' . __('Car Registration') . '</h2>';
@dannyconnolly
dannyconnolly / Add css class to top selling products
Created April 13, 2015 13:08
Add css class to top selling products
/**
* Add topseller class to product
**/
$query = "SELECT ID FROM {$wpdb->posts} p
INNER JOIN {$wpdb->postmeta} pm ON ( pm.post_id = p.ID AND pm.meta_key='total_sales' )
WHERE p.post_type = 'product'
AND p.post_status = 'publish'
ORDER BY pm.meta_value+0 DESC
LIMIT 10";
@dannyconnolly
dannyconnolly / Import an sql dump file with PHP
Last active August 29, 2015 14:10
Import an sql dump file with PHP
// Name of the file
$filename = 'DUMPFILEHERE.sql';
// MySQL host
$mysql_host = 'DB_HOST';
// MySQL username
$mysql_username = 'DB_USER';
// MySQL password
$mysql_password = 'DB_PASSWORD';
// Database name
$mysql_database = 'DB_NAME';
//* Add walker class that displays menu item descriptions
class Menu_With_Description extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;