This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // If a number is a whole number, return the number | |
| // If a number is a decimal, return the number to two decimal places | |
| function formatDecimals(number) { | |
| if(Math.round(number) !== number) { | |
| return number.toFixed(2); | |
| } else { | |
| return number; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Usage: | |
| // insertAtCaret('some text to insert'); | |
| (function ($, undefined) { | |
| function insertAtCaret(text) { | |
| var $focused = $(':focus'); | |
| var focusedCursorPosition = $focused.getCursorPosition(); | |
| var focusedContent = $focused.val(); | |
| var focusedNewContent = focusedContent.substr(0, focusedCursorPosition) + ' ' + string + focusedContent.substr(focusedCursorPosition); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter('upload_size_limit', 'd7_increase_upload'); | |
| function d7_increase_upload() { | |
| // 250mb | |
| return '262144000'; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Use an ACF image field | |
| // Set the 'return value' option to "array" (this is the default) | |
| // This example uses three image sizes, called medium, medium_large, thumbnail | |
| $imageobject = get_field('image'); | |
| if( !empty($imageobject) ): | |
| echo '<img alt="' . $imageobject['title'] . '" src="' . $imageobject['sizes']['medium'] . '" srcset="' . $imageobject['sizes']['medium_large'] .' '. $imageobject['sizes']['medium_large-width'] .'w, '. $imageobject['sizes']['medium'] .' '. $imageobject['sizes']['medium-width'] .'w, '. $imageobject['sizes']['thumbnail'] .' '. $imageobject['sizes']['thumbnail-width'] .'w">'; | |
| endif; | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var request = $.get('http://wp-recipes/wp-json/wp/v2/posts', {}, function(data, textStatus, jqXHR){ | |
| // Do some stuff | |
| }, 'json'); | |
| request.success(function(result) { | |
| console.log('success:'); | |
| console.log(result); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Dynamically get the video length, and do something to a video X seconds before it ends | |
| $('.video').on('timeupdate', function(event) { | |
| var timeFromVideoEnd = 2000; | |
| var current = Math.round(event.target.currentTime * 1000); | |
| var total = Math.round(event.target.duration * 1000); | |
| if ( ( total - current ) < timeFromVideoEnd ) { | |
| $body.addClass('fade-video-out'); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // One and done smooth scrolling for anchor links | |
| // Taken from: https://css-tricks.com/snippets/jquery/smooth-scrolling/ | |
| $(function() { | |
| $('a[href*="#"]:not([href="#"])').click(function() { | |
| if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { | |
| var target = $(this.hash); | |
| target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); | |
| if (target.length) { | |
| $('html, body').animate({ | |
| scrollTop: target.offset().top |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {# Include in views like so: {% include 'partials/image-srcset.twig' with {image_id: post.get_field('hero_background_image'), class: 'hero__background'} %} #} | |
| {# To print image object: {{post.get_field('hero_background_image')|print_r}} #} | |
| <img class="{{class}}" alt="{{TimberImage(image_id).alt}}" | |
| src="{{ TimberImage(image_id).src('large') }}" | |
| srcset="{{ TimberImage(image_id).src('xlarge') }} {{ image_id['sizes']['xlarge-width'] }}w, | |
| {{ TimberImage(image_id).src('hero') }} {{ image_id['sizes']['hero-width'] }}w, | |
| {{ TimberImage(image_id).src('large') }} {{ image_id['sizes']['large-width'] }}w | |
| " /> |