Skip to content

Instantly share code, notes, and snippets.

View davidchase's full-sized avatar
📺
Working from home

David Chase davidchase

📺
Working from home
View GitHub Profile
@davidchase
davidchase / getPageBySlug.php
Created March 4, 2013 19:50
Wordpress get page id by its slug
<?php
//get page id's by their slug
function id_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page):
return $page->ID;
else:
return null;
endif;
}
// use for patterns:
// *gmail.com*
// *mail.google.com*
// *google.com*mail*
window.fluid.dockBadge = '';
setTimeout(updateDockBadge, 3000);
setInterval(updateDockBadge, 15000);
function updateDockBadge() {
@davidchase
davidchase / paginationFunc.php
Created March 20, 2013 13:42
pagination inside of a function or shortcode
<?php
function paginationFunc() {
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; // setup pagination
$the_query = new WP_Query( array(
'post_type' => 'name_of_post_type', // post type custom or native
'orderby' => 'date', // how to order
'order' => 'DESC', // order ASC or DESC
'paged' => $paged,
'posts_per_page' => 2) //pages to show
);
@davidchase
davidchase / commitModified.bash
Created March 22, 2013 15:56
Committing only modified files in svn.. I use this to avoid committing .DS_Store files and it comes in handy a few times. Using sed and xargs.
Filename without spaces:
svn st | sed -n 's/^M//p' | xargs svn commit -m "modified"
Filename with spaces:
svn st | sed -n 's/$/"/; s/^M */"/p' | xargs svn commit -m "modified"
@davidchase
davidchase / bodyMenuClass.php
Created March 27, 2013 19:33
Adds the user input class from appearance>menu to the body class group, using add_filter and body_class
add_filter('body_class','get_custom_menu_classes');
function get_custom_menu_classes($classes)
{
$items = wp_get_nav_menu_items( 7 );
foreach ($items as $item):
$menuClasses = $item->classes;
$objectId = $item->object_id.' ';
if ( is_page($item->object_id) ):
@davidchase
davidchase / README.md
Last active April 26, 2024 04:53
cookie obj from the folks at MDN, awesome!

Mozilla Developer Network

Cookies object

Forked from here

A complete cookies reader/writer framework with full unicode support.

This framework is released under the GNU Public License, version 3 or later.

@davidchase
davidchase / README.md
Created April 10, 2013 12:33
google maps from address to latlng

Geocoder

The function converts an address that a user enters to geocode aka lat/lng.

The results stored in a variable to later use in a application sense.

jQuery(document).ready(function($){
var _custom_media = true,
_orig_send_attachment = wp.media.editor.send.attachment;
$('.stag-metabox-table .button').click(function(e) {
var send_attachment_bkp = wp.media.editor.send.attachment;
var button = $(this);
var id = button.attr('id').replace('_button', '');
_custom_media = true;
wp.media.editor.send.attachment = function(props, attachment){
if ( _custom_media ) {
@davidchase
davidchase / README.md
Last active December 16, 2015 12:28
Quick no dependency test for flash players installed... to test in chrome disable flash in chrome://plugins/ and console.log the variable "hasFlash"

Has Flash?

Test the user to see if they have flash player installed on their machine.

Vanilla JS no dependcies

Can be test in Chrome by simple disabling flash inside plugins like so:

In the address chrome://plugins/ then select Disable under Adobe Flash player.

@davidchase
davidchase / README.md
Last active January 12, 2022 10:00
simple hash change with scrolling, using jQuery

#Hash Change onScroll

Reminder:

Need to add mootools version too :)

Change the value of the url by scrolling through div's data-id or #