Skip to content

Instantly share code, notes, and snippets.

Avatar

Tim Gieseking timstl

View GitHub Profile
@timstl
timstl / .gitignore
Last active Sep 6, 2018
WordPress .gitignore template; A compilation of many examples customized to fit our needs.
View .gitignore
# 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 Mar 29, 2019
Exclude featured posts from main WordPress blog loop
View excludefeatured.php
/**
* 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 );
}
}
View relatedposts.php
@timstl
timstl / scrollmagic.datatotarget.js
Created Nov 9, 2017
ScrollMagic: Animate element using HTML data attribute
View scrollmagic.datatotarget.js
// 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 Nov 9, 2017
ScrollMagic: Toggle class with HTML data attribute.
View scrollmagic.dataclasstoggle.js
// 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 Aug 24, 2016
Function to convert ACF image field into image tag with srcset.
View the_field_srcset.php
<?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 Mar 31, 2016
Determine if currently viewing a WordPress blog page (home, archive, search, single post).
View is_blog_page()
<?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 Dec 5, 2018
jquery.backtotop.js
View jquery.backtotop.js
/*
back to top
usage: $('#main').backtotop();
use localScroll plugin for smooth scrolling
style in CSS.
*/
;(function($) {
$.fn.backtotop = function(options) {
View gist:c2dc5541094e99c72ee4
/*
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 Sep 15, 2018
Toggle class based on scroll position. Add your effects and style changes to your CSS.
View jquery.scrollclass.js
(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;