Skip to content

Instantly share code, notes, and snippets.

@salcode
salcode / gist:6912619
Last active November 8, 2023 01:11
jQuery function to remove all "data-" attributes from a given element
// Note: This is an improved version provided by @laurentmuller in the comments below.
// removes all data attributes from a target element
// example: removeDataAttributes('#user-list');
function removeDataAttributes(target) {
var $target = $(target);
// Loop through data attributes.
$.each($target.data(), function (key) {
// Because each key is in camelCase,
@salcode
salcode / gist:7164690
Last active May 12, 2017 22:12
Genesis WordPress Framework adding custom classes to markup This gist was originally created as an example of what I perceived to be an inconsistent behavior, my error was failing to attach my code to action `genesis_setup`. Corrected version now appears below. 20131027 - merged Gary Jones's fork with corrections and refactoring
<?php
/*
* Examples to add custom classes to Genesis WordPress Framework Markup when using HTML5 output
*/
add_action( 'genesis_setup', 'srf_add_cust_classes', 15 ); // Priority 15 ensures it runs after Genesis itself has setup.
function srf_add_cust_classes() {
add_filter( 'genesis_attr_site-inner', 'srf_attr_site_inner' );
add_filter( 'genesis_attr_content-sidebar-wrap', 'srf_attr_content_sidebar_wrap' );
add_filter( 'genesis_attr_content', 'srf_attr_content' );
add_filter( 'genesis_attr_sidebar-primary', 'srf_attr_sidebar_primary' );
@salcode
salcode / publish-posts-increment-times.php
Last active December 26, 2015 20:29
WordPress code to increment Published times by one second for each post when multiple posts are Published in one call. This is a work-around for https://core.trac.wordpress.org/ticket/8107
<?php
add_action( 'transition_post_status', 'srf_publish_post_unique_date', 10, 3 );
function srf_publish_post_unique_date( $new_status, $old_status, $post ) {
// only perform operation when post is
// changing to a status of 'publish'
// otherwise (abort)
if ( 'publish' !== $new_status ) { return; }
@salcode
salcode / jquery-plugin-template.js
Created November 7, 2013 13:40
My starter template for a jQuery plugin
/*
* jQuery('a').pluginName();
* or
* jQuery('a').pluginName({
* className: 'alternative-class-name'
* });
*/
;(function ( $, window, document ) {
$.fn.pluginName = function( options ) {
@salcode
salcode / touch-device-detect.js
Created November 20, 2013 21:06
Touch Device Detection
// requires Modernizr be loaded http://modernizr.com/download/
// with Misc. => Touch Events support
function isTouchDevice() {
return (
// detects touch events (not present on Windows Mobile)
Modernizr.touch
||
// detects Windows Mobile touch support
navigator.msMaxTouchPoints
@salcode
salcode / functions-snippet-sticky-posts-only.php
Last active January 2, 2016 12:19
Code to add to your functions.php to only display Sticky posts on your main blog page
<?php
// add the following code to your functions.php file
add_action( 'pre_get_posts', 'fe_pre_get_posts_sticky_only' );
function fe_pre_get_posts_sticky_only( $query ) {
if (
$query->is_main_query()
&& $query->is_home()
) {
@salcode
salcode / youtube-oembed-html5-param.php
Created January 22, 2014 21:36
Corrective code for WordPress YouTube oEmbed on a webpage that has CSS transform translate.
<?php
// add parameter html5=1 to oembed YouTube requests as per
// http://stackoverflow.com/questions/17747443/css-transform-translate-breaking-youtube-embedded-video
// using modified version of code on http://www.alittleofboth.com/2013/06/modifying-youtube-video-display-in-wordpress/
add_filter( 'oembed_result', 'youtube_oembed_html5_parameter', 10, 3);
function youtube_oembed_html5_parameter($data, $url, $args = array()) {
// add &html5=1 parameter
$data = preg_replace('/(youtube\.com.*)(\?feature=oembed)(.*)/', '$1?' . apply_filters("hyrv_extra_querystring_parameters", "feature=oembed&amp;html5=1&amp;") . 'rel=0$3', $data);
return $data;
}
@salcode
salcode / custom-tax-example.php
Last active January 4, 2016 05:59
Custom Tax for testing Custom Permalinks plugin for bug report.
<?php
// Register Custom Taxonomy
function custom_taxonomy() {
$labels = array(
'name' => _x( 'Taxonomies', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Taxonomy', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Taxonomy', 'text_domain' ),
'all_items' => __( 'All Items', 'text_domain' ),
'parent_item' => __( 'Parent Item', 'text_domain' ),
@salcode
salcode / dump-mamp-mysql-dbs.sh
Created February 21, 2014 20:30
Shell Script to dump all MAMP DBs into separate files
# based on http://www.commandlinefu.com/commands/view/2916/backup-all-mysql-databases-to-individual-files
# but modified for the MAMP path and to include default root/root as username and password
for I in $(/Applications/MAMP/Library/bin/mysql -u root -proot -e 'show databases' -s --skip-column-names); do /Applications/MAMP/Library/bin/mysqldump -u root -proot $I | gzip > "$I.sql.gz"; done
@salcode
salcode / .gitignore
Last active February 4, 2018 21:27
.gitignore for a WordPress project managed with Siteground git deployment
# ignore all files starting with .
\.*
# include .gitignore (i.e. do NOT ignore)
!.gitignore
# ignore all files that start with ~
~*
# ignore node/grunt dependencies