Skip to content

Instantly share code, notes, and snippets.

/**
* Makes the filter bar sticky when it reaches the top of the screen by scrolling, and un-sticks it if you scroll above the screen.
* Also fills in the primary nav bar when the filter bar becomes sticky.
*/
function stickyFilterBar() {
window.filterBarIsFixed = false;
var filterSortBar = document.querySelector(".filter-sort-bar"); //Parent element
if (filterSortBar !== null) {
var topButtonBar = document.querySelector(".top-button-bar");
var topButtonBarHeight = jQuery(topButtonBar).height();
@bpb54321
bpb54321 / Youtube Video Embed Responsive Styling
Created August 14, 2016 15:44
Youtube video embed preserves aspect ratio across all screen sizes.
.youtube-video-wrap {
width: 100%;
max-width: 640px;
margin: 3rem auto;
}
.video-container {
position: relative;
padding-bottom: 56.25%; //16:9 aspect ratio, 9/16 = .5625. Padding is percentage of container width
height: 0;
overflow: hidden;
@bpb54321
bpb54321 / get_image_widths_and_urls.php
Last active August 15, 2016 14:55
Helper function for getting widths and url's of all the available sizes of an image in WordPress.
/**
* Helper function for getting the widths and url's of all the available crops of an image.
* @param Number $id: The id of the image that you need the info for
* @return Array An associative array with array["widths"] containing an array of widths and array["urls"] containing the corresponding image urls.
*/
function get_image_widths_and_urls($id) {
//Get all the possible image sizes
$image_size_array = get_intermediate_image_sizes();
//error_log('--------------------$image_size_array------------------------');
//error_log( var_export($image_size_array, true) );
@bpb54321
bpb54321 / create_responsive_img_tag.php
Created August 24, 2016 19:09
Given an image ID and some other parameters, returns as a string a responsive image tag using the srcset and sizes attributes.
/**
* Returns a string of an <img> tag with src, srcset and sizes attributes set.
* @param $attachment_id int The WordPress id for the attachment.
* @param $alt_string String The alt string for the image tag, e.g. "My image"
* @param string $class_string A string of classes to apply to the <img>
* @param array $sizes_to_exclude An array of strings, where each string is a named WordPress intermediate image size that you want to exclude from the srcset attribute.
* @param string $sizes_string The string that will become the sizes attribute of the <img>
* @return string
*/
function create_responsive_img_tag( $attachment_id = -1, $alt_string = '', $class_string = '', $sizes_to_exclude = [], $sizes_string = '' ) {
@bpb54321
bpb54321 / create_deferred_image_tag.php
Created September 21, 2016 21:21
Outputs HTML for image tags that load a WordPress medium size image on initial load, then a separte javascript file (image_deferred.js) loads in the srcset and sizes attributes.
/**
* Helper function for getting the widths and url's of all the available crops of an image.
* @param Number $id : The id of the image that you need the info for
* @param Array $image_sizes_to_exclude An array of strings with the names of image sizes to exclude from the output
* @return Array An indexed array, where at each index there is an associative array with array["width"] containing an image width and array["url"] containing the corresponding image url.
* Example: Array(
* [0] => Array(
* [width] => 300
* [url] => http://placehold.it/50x50
* ),
@bpb54321
bpb54321 / load-deferred-images.js
Created September 21, 2016 21:23
Working in tandem with create_deferred_img_tag.php, takes data from data-srcset and data-sizes of <img> elements and assigns them to the real srcset and sizes after the page has loaded lightweight images initially.
/**
* Given a jQuery selector string corresponding to a collection of images, moves the values from the image attributes
* data-srcset and data-sizes to srcset and sizes, thus loading the appropriate images in a deferred manner. Requires
* jQuery.
* @param String selector A String used as a jQuery selector for a collection of images.
* @param startIndex The start index of the subset of the images you want to load from the collection returned from the
* selector string.
* @param endIndex The end index of the subset of the images you want to load from the collection returned from the
* selector string. Put the same value for startIndex and endIndex if you only want a single image to be loaded.
* If not supplied, will be calculated as the last index in the collection.
@bpb54321
bpb54321 / admin.php
Created September 23, 2016 19:05
WordPress Logo Uploader in Theme Customizer
/***************CUSTOMIZE THE THEME CUSTOMIZER************/
function refinestl_customize_register( $wp_customize ) {
// Do stuff with $wp_customize, the WP_Customize_Manager object.
$wp_customize->add_section( 'logo_section', array(
'title' => __( 'Logos', 'textdomain' ),
'priority' => 101,
) );
$wp_customize->add_setting( 'site_logo', array(
'type' => 'theme_mod',
@bpb54321
bpb54321 / _cta-widget.scss
Created September 23, 2016 19:09
Footer CTA
.call-to-action {
background-color: $fawn;
padding-bottom: 2em;
padding-top: 2em;
@include breakpoint(medium) {
padding-left: 15%;
padding-right: 15%;
}
h6 {
width: 55%;
@bpb54321
bpb54321 / rsync.txt
Last active November 15, 2017 19:00
Basic Rsync
You will need to place your public SSH key on the server for authentication for this to work.
See this article: https://www.digitalocean.com/community/tutorials/how-to-copy-files-with-rsync-over-ssh
rsync -rv -e 'ssh -p 1111' user@SOURCE:/path/ /Users/brianblosser/DESTINATION/
Use rsync to transfer files from an FTP source to a local destination
-r: recurse into directories
-v: verbose
@bpb54321
bpb54321 / image-cover.scss
Last active February 22, 2017 02:05
Styles for Object-Fit: Cover Styling of Responsive Images
/**
* If this mixin is applied to an <img> tag that is a child of a parent element
* with a fixed height or changing aspect ratio, it will scale the image to cover
* the smallest dimension, and crop the image through the overflow: hidden
* rule on the parent.
* You must apply the mixin image-cover-parent to the parent in order for
* image-cover to work on the child.
*/
@mixin image-cover() {
display: block;