Skip to content

Instantly share code, notes, and snippets.

View pacotole's full-sized avatar

Pacotole pacotole

View GitHub Profile
@zohararad
zohararad / zepto.queue.js
Created August 21, 2013 08:31
jQuery queues port to Zepto. Use this to get Spine.js working with Zepto (needs Zepto deferred as well), or queue animations etc. Note that this code is a simple copy and paste of relevant functionality from jQuery 2.0.3
(function($){
// jQuery Data object
var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
rmultiDash = /([A-Z])/g,
expando = "Zepto" + ( '1.0' + Math.random() ).replace( /\D/g, ""),
optionsCache = {},
core_rnotwhite = /\S+/g,
core_deletedIds = [],
core_push = core_deletedIds.push;
@hlashbrooke
hlashbrooke / function.php
Last active July 4, 2022 21:35
WordPress: Display posts in a random order, but retain persistent pagination
<?php
session_start();
add_filter( 'posts_orderby', 'randomise_with_pagination' );
function randomise_with_pagination( $orderby ) {
if( is_front_page() ) {
// Reset seed on load of initial archive page
// Bootstrap Mid-Small - col-ms-* - the missing grid set for Bootstrap3.
//
// This is a hack to fill the gap between 480 and 760 pixels - a missing range
// in the bootstrap responsive grid structure. Use these classes to style pages
// on cellphones when they transition from portrait to landscape.
//
// NOTE: Here I use SASS instead of LESS for styling. To convert to LESS
// replace '$screen' with '@screen' and '$grid' with '@grid'.
//
// See https://github.com/twbs/bootstrap/issues/10203 for more info.
<?php
if (!is_blog_installed()) { return; }
if ('http://' . $_SERVER['SERVER_NAME'] . '/wp' == get_option('home')) {
update_option('siteurl', 'http://' . $_SERVER['SERVER_NAME'] . '/wp');
update_option('home', 'http://' . $_SERVER['SERVER_NAME']);
update_option('upload_path', $_SERVER['DOCUMENT_ROOT'] . '/media');
update_option('upload_url_path', 'http://' . $_SERVER['SERVER_NAME'] . '/media');
update_option('permalink_structure', '/%postname%/');
}
@jonathandixon
jonathandixon / Grunt-Cordova-CLI.md
Last active January 5, 2021 22:00
Using Grunt with a Cordova 3 project.

Grunt and Cordova 3

The advantages of using Grunt with Cordova:

  1. It simplifies working with the cordova cli.
  2. It provides a mechanism to copy platform customization to the platforms directory without having to commit the generated plugins and platforms directories to version control.
  3. It provides a way to watch resources and automatically run cordova commands.

Stack Overflow: .gitignore for PhoneGap/Cordova 3.0 projects - what should I commit?

@DevinWalker
DevinWalker / woocommerce-optimize-scripts.php
Last active June 16, 2025 08:57
Only load WooCommerce scripts on shop pages and checkout + cart
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@schilke
schilke / functions.php
Last active February 23, 2023 18:53
How to load CSS files asynchronously in WordPress (using Scott Jehl's "loadCSS")
<?php
// This is the cleaner code per request of a thread in the LinkedIn group "WordPress"
// ...
// register and enqueue loadCSS
function load_scripts_and_styles() {
// register loadCSS
wp_register_script( 'load-css-async', get_stylesheet_directory_uri() . '/path/to/js/loadCSS.js', array(), '', false );
@magnific0
magnific0 / wp_usermeta.md
Last active February 6, 2025 02:30
Show and Edit User Meta in Wordpress

Show and Edit User Meta in Wordpress

Description

This simple procedure will allow you to:

  1. Display user meta fields under in the user list as additional columns (Users > All Users).
  2. Display these fields on user profiles.
  3. Edit these fields under user edit.

This method works completely without plugins and involves just some functions and hooks in functions.php. Plugins like "User Meta Display" achieve this to some level, but treat custom meta fields completely different from the regular fields. They are shown and edited in seperate environment and fail to show the meta data is a table list. This method integrates custom user meta along with regular user (meta).

@cansadadeserfeliz
cansadadeserfeliz / admin.py
Created October 9, 2014 17:05
Make all fields readonly for Django Admin
class StudentAnswersAdmin(admin.ModelAdmin):
def get_readonly_fields(self, request, obj=None):
# make all fields readonly
readonly_fields = list(set(
[field.name for field in self.opts.local_fields] +
[field.name for field in self.opts.local_many_to_many]
))
if 'is_submitted' in readonly_fields:
readonly_fields.remove('is_submitted')
@fieldoffice
fieldoffice / sub-menu-wrap
Last active March 18, 2025 18:03
Wordpress - add div wrapper around sub-menu
/* EXTEND SUBNAV
******************************************/
class submenu_wrap extends Walker_Nav_Menu {
function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<div class='sub-menu-wrap'><ul class='sub-menu'>\n";
}
function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);