Skip to content

Instantly share code, notes, and snippets.

View timstl's full-sized avatar

Tim Gieseking timstl

View GitHub Profile
@timstl
timstl / .gitignore
Last active September 6, 2018 14:09
WordPress .gitignore template; A compilation of many examples customized to fit our needs.
# ignore everything in the root except the "wp-content" directory.
/*
!wp-content/
# ignore everything in the "wp-content" directory, except:
# plugins and themes directories
wp-content/*
!wp-content/plugins/
!wp-content/themes/
wp-content/themes/twenty*
@timstl
timstl / excludefeatured.php
Last active March 29, 2019 20:49
Exclude featured posts from main WordPress blog loop
/**
* Exclude featured posts from main blog loop
*/
function bt_exclude_featured_from_blog_index( $query ) {
if ( ! is_admin() && $query->is_home() && $query->is_main_query() ) {
$post_ids = bt_featured_post_ids();
if ( ! empty( $post_ids ) ) {
$query->set( 'post__not_in', $post_ids );
}
}
@timstl
timstl / relatedposts.php
Last active April 1, 2019 21:37
related posts
@timstl
timstl / scrollmagic.datatotarget.js
Created November 9, 2017 20:33
ScrollMagic: Animate element using HTML data attribute
// ScrollMagic
const controller = new ScrollMagic.Controller();
// Animate an object to a y or x value
// Usage: data-to-target="y:-100"
// Optional: data-to-target-mobile="y:-50" (requires SSM)
// Optional: data-duration="50%"
// Optional: data-trigger-element="#someDiv" (defaults to parent)
$('[data-to-target]').each(function() {
const $this = $(this);
@timstl
timstl / scrollmagic.dataclasstoggle.js
Last active November 9, 2017 20:45
ScrollMagic: Toggle class with HTML data attribute.
// ScrollMagic
const controller = new ScrollMagic.Controller();
// Animate an object to a y or x value
// Usage: data-to-target="y:-100"
// Optional: data-to-target-mobile="y:-50" (requires SSM)
// Optional: data-duration="50%"
// Optional: data-trigger-element="#someDiv" (defaults to parent)
// Optional: Adjust animation offset using data-animation-offset="X"
$('[data-to-target]').each(function() {
@timstl
timstl / the_field_srcset.php
Last active August 24, 2016 20:53
Function to convert ACF image field into image tag with srcset.
<?php
/*
Usage: the_field_srcset('field_name');
ACF field should return Image ID.
*/
function the_field_srcset($field, $before='', $after='', $size = 'full', $echo = true) {
if (get_field($field)) {
$img = wp_get_attachment_image(get_field($field), $size);
@timstl
timstl / is_blog_page()
Last active March 31, 2016 14:56
Determine if currently viewing a WordPress blog page (home, archive, search, single post).
<?php
function is_blog_page($single=true, $four04=true) {
if ((is_home() || is_archive() || is_search()) && !is_post_type_archive()) {
return true;
}
if ($single === true && is_singular('post')) {
return true;
}
@timstl
timstl / jquery.backtotop.js
Last active December 5, 2018 21:39
jquery.backtotop.js
/*
back to top
usage: $('#main').backtotop();
use localScroll plugin for smooth scrolling
style in CSS.
*/
;(function($) {
$.fn.backtotop = function(options) {
@timstl
timstl / gist:c2dc5541094e99c72ee4
Created March 9, 2015 15:20
jquery.vadjust.js
/*
vadjust plugin.
adjust top margin on vertically centered elements.
var $vadj = $('[data-vadjust="true"]');
if ($vadj.length > 0) { $vadj.vadjust(); }
*/
;(function($) {
$.fn.vadjust = function(options)
@timstl
timstl / jquery.scrollclass.js
Last active September 15, 2018 14:38
Toggle class based on scroll position. Add your effects and style changes to your CSS.
(function($) {
$.fn.scrollclass = function(options) {
var opts = $.extend({}, $.fn.scrollclass.defaults, options),
$this = this,
state2 = false;
$(document)
.scroll(function() {
if (state2 == false && $(this).scrollTop() > opts.pos) {
state2 = true;