Skip to content

Instantly share code, notes, and snippets.

@dannyconnolly
dannyconnolly / Adds class to the current section that is visible on screen for one page website
Last active August 29, 2015 14:03
Adds class to the current section that is visible on screen for one page website
var sections = $('.section')
, nav = $('.menu-main-navigation-container')
, nav_height = nav.outerHeight();
$(window).on('scroll', function() {
var cur_pos = $(this).scrollTop();
sections.each(function() {
var top = $(this).offset().top - nav_height,
bottom = top + $(this).outerHeight();
@dannyconnolly
dannyconnolly / Smooth Scroll On Anchor Links
Created June 16, 2014 23:06
Smooth Scroll On Anchor Links
@dannyconnolly
dannyconnolly / SassMeister-input.sass
Created June 14, 2014 00:13
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.2)
// Compass (v1.0.0.alpha.17)
// ----
// Add vendor prefixes to keyframes
@mixin keyframe ($animation-name)
@-webkit-keyframes #{$animation-name}
@content
@-moz-keyframes #{$animation-name}
@dannyconnolly
dannyconnolly / Create an admin user in wordpress with SQL
Created June 12, 2014 13:21
Create an admin user in wordpress with SQL
INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('ID', 'USERNAME', MD5('PASSWORD'), 'USERNICENAME', 'USEREMAIL', '', '0000-00-00 00:00:00', '', '0', 'DISPLAYNAME');
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, 'ID', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, 'ID', 'wp_user_level', '10');
@dannyconnolly
dannyconnolly / Check if page is parent, child in wordpress
Created April 30, 2014 15:00
Check if page is parent, child in wordpress
function is_tree($pid) {
// $pid = The ID of the page we're looking for pages underneath
global $post;
// load details about this page
if(is_page()&&($post->post_parent==$pid||is_page($pid)))
return true; // we're at the page or at a sub page
else
return false; // we're elsewhere
};
@dannyconnolly
dannyconnolly / Detecting touch events with js
Created March 29, 2014 08:01
Detecting touch events with js
(function(window){
// check for touch
if (Modernizr.touch) {
// run the forEach on each figure element
[].slice.call(document.querySelectorAll("figure")).forEach(function(el,i){
// check if the user moves a finger
var fingerMove = false;
@dannyconnolly
dannyconnolly / Only load contact form 7 script when needed
Last active August 29, 2015 13:57
Only load contact form 7 scripts when needed in wordpress
/**
* Only load contact form 7 script when needed
*/
function cf7_dequeue_scripts() {
$load_scripts = false;
if( is_singular() ) {
$post = get_post();
@dannyconnolly
dannyconnolly / Remove query strings from static resources in wordpress
Created March 19, 2014 10:52
Remove query strings from static resources in wordpress
function _remove_script_version( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
@dannyconnolly
dannyconnolly / Check if is child page, parent page or ancestor page
Created March 2, 2014 13:56
Check if is child page, parent page or ancestor page
/**
* Check if is child page, parent page or ancestor page
*/
function is_in_heirarchy() {
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];
@dannyconnolly
dannyconnolly / Sass Mixins
Created February 27, 2014 23:32
Sass Mixins
@mixin breakpoint($point) {
@if $point == large {
@media (min-width: 64.375em) { @content; }
}
@else if $point == medium {
@media (min-width: 50em) { @content; }
}
@else if $point == small {
@media (min-width: 37.5em) { @content; }
}