Skip to content

Instantly share code, notes, and snippets.

View jaclyntan's full-sized avatar
💌
Enquiries: jaclyntan02@gmail.com

Jaclyn Tan jaclyntan

💌
Enquiries: jaclyntan02@gmail.com
View GitHub Profile
@jaclyntan
jaclyntan / prism-darktooth.css
Created November 4, 2020 09:31
Darktooth theme for Prism
/* Generated with http://k88hudson.github.io/syntax-highlighting-theme-generator/www */
/* http://k88hudson.github.io/react-markdocs */
/**
* @author k88hudson
*
* Based on prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/
/*********************************************************
@jaclyntan
jaclyntan / vh.js
Created June 30, 2020 07:45
Store viewport height for mobile (ios safari)
/*!
♡♡♡♡♡♡♡♡♡♡♡
♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
store viewport height for mobile
♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
♡♡♡♡♡♡♡♡♡♡♡
*/
// First we get the viewport height and we multiple it by 1% to get a value for a vh unit
let vh = window.innerHeight;
let currentWidth = window.innerWidth;
@jaclyntan
jaclyntan / simple parallax
Created June 30, 2020 07:43
Parallax any element on the page using jquery and data attributes
/*!
♡♡♡♡♡♡♡♡♡♡♡
♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
Parallax functionality
♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
♡♡♡♡♡♡♡♡♡♡♡
*/
$('.parallax').on('mouseover', function () {
$(this).css('z-index', '99');
@jaclyntan
jaclyntan / wp-ajax-get.js
Last active June 30, 2020 07:41
Snippet to get the next page using ajax in WordPress
/*!
♡♡♡♡♡♡♡♡♡♡♡
♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
Async functionality
♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
♡♡♡♡♡♡♡♡♡♡♡
*/
$(document).on('click', '#page a:not([target="_blank"]):not([href="#"]):not(.btn), [href^="/"]', function (e) {
var $this = $(this),
$page = $this.attr('href'),
@jaclyntan
jaclyntan / gist:855ccf013efa5c9da15b32e6f1d4a798
Created August 13, 2019 09:00
Get the ID from posts, pages, and archives in WordPress
if ( is_home() && ! in_the_loop() ) {
$ID = get_option('page_for_posts');
} elseif ( is_post_type_archive()) {
$query = get_queried_object();
$slug = $query->name;
$pageobj = get_page_by_title($slug);
$ID = $pageobj->ID;
} else {
$ID = get_the_ID();
}
@jaclyntan
jaclyntan / wp-autobsrows
Created February 1, 2017 03:11
Automatic bootstrap rows in the WordPress loop
<?php
$counter = 0;
while ( have_posts() ) : the_post();
$counter++;
if ($counter === 1) {
echo '<div class="row">';//start the row
}
echo '<div class="col-sm-__NAME__">';//start the col//
get_template_part( 'template-parts/content', 'page' );
@jaclyntan
jaclyntan / wpimgsrcset
Created February 1, 2017 03:08
WordPress img srcset
<?php
$id = get_post_thumbnail_id();
$size = 'medium';
$img_src = wp_get_attachment_image_url( $id, $size );
$img_srcset = wp_get_attachment_image_srcset( $id, $size );
$title = get_post($id)->post_title;
$alt = get_post_meta($id, '_wp_attachment_image_alt')[0];
?>
<img src="<?php echo esc_url( $img_src ); ?>"
srcset="<?php echo esc_attr( $img_srcset ); ?>"
@jaclyntan
jaclyntan / offsetwploop
Created February 1, 2017 03:05
Offset the WordPress loop
<?php
$number_of_posts_per_page = 9;
$initial_offset = 1;
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
// Use paged if this is not on the front page
$number_of_posts_past = $number_of_posts_per_page * ($paged - 1);
$off = $initial_offset + (($paged > 1) ? $number_of_posts_past : 0);
function get_video_thumbnail( $src ) {
$url_pieces = explode('/', $src);
if ( $url_pieces[2] == 'vimeo.com' ) { // If Vimeo
$id = $url_pieces[3];
$hash = unserialize(file_get_contents('http://vimeo.com/api/v2/video/' . $id . '.php'));
$thumbnail = $hash[0]['thumbnail_large'];
} elseif ( $url_pieces[2] == 'www.youtube.com' ) { // If Youtube
$extract_id = explode('?', $url_pieces[3]);
$watchid = $extract_id[1];
@jaclyntan
jaclyntan / gulpfile.js
Created December 27, 2016 20:13
One gulpfile to rule them all: Wordpress edition
"use strict";
// . . . .
// ,`,`,`,`,
//. . . . `\`\`\`\;
//`\`\`\`\`, ~|;!;!;\!
// ~\;\;\;\|\ (--,!!!~`! .
//(--,\\\===~\ (--,|||~`! ./
// (--,\\\===~\ `,-,~,=,:. _,//
// (--,\\\==~`\ ~-=~-.---|\;/J,