Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Vyygir's full-sized avatar

Matt Royce Vyygir

View GitHub Profile
@Vyygir
Vyygir / sharing-links.php
Last active February 7, 2016 14:18
Post Sharing for Programmers original class before plugin creation
@Vyygir
Vyygir / preload.js
Last active April 12, 2016 10:59
Relatively simple image preloader
function preloadImages() {
var buffer, images;
buffer = new Image();
images = document.getElementsByTagName('img');
if (images.length) {
for (var i = 0, l = images.length; i < l; i++) {
buffer.src = images[i].src;
}
@Vyygir
Vyygir / .gitignore
Created August 9, 2016 10:48
.gitignore for working environment (rough draft)
### OS X ###
*.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
@Vyygir
Vyygir / [WP] Force download headers
Last active January 31, 2017 10:00
A function that hooks into WordPress and, when a $_GET request with a key of "download" and a value that contains a Base64 encoded array of semi-colon separated file URLS is passed, generates the ZIP on the fly and downloads it
add_action('wp', 'handle_all_file_downloads');
function handle_all_file_downloads() {
if (isset($_GET) && isset($_GET['download'])) {
$urls = base64_decode($_GET['download']);
if ($urls) {
$urls = (strpos($urls, ';') !== false) ? explode(';', $urls) : array($urls);
$path = wp_upload_dir();
$zip = new ZipArchive();
@Vyygir
Vyygir / custom-tax-dropdown.php
Last active February 24, 2017 14:55
[WP] Custom taxonomy dropdown menu
<?php
$dropdown_taxonomy = 'YOUR_TAXONOMY_NAME';
$dropdown_terms = get_terms($dropdown_taxonomy);
$archive_url = home_url('/'); // change this to the URL the user should go to if they select "All"
if (!empty($dropdown_terms)) :
?>
<select id="term-dropdown" class="term-dropdown">
<option value="<?php echo $archive_url; ?>">All</option>
<?php foreach ($dropdown_terms as $dropdown_term) : ?>
@Vyygir
Vyygir / time_elapsed_string.php
Last active February 10, 2017 10:06 — forked from zachstronaut/gist:1184831
Get a relative time string in PHP without a lot of if/else or switch/case
<?php
/**
* time_elapsed_string()
*
* @author Zachary Johnson
* @link http://www.zachstronaut.com/posts/2009/01/20/php-relative-date-time-string.html
*
* @author Vyygir
* @link https://gist.github.com/Vyygir/5a70d8007141cf49541b967c8e9a2280
* @description I had to modify this slightly from the previous version, as it was causing errors
@Vyygir
Vyygir / is_nth_level_page.php
Created February 20, 2017 13:56
Quick, small function to check if your page is currently the nth child
<?php
/**
* is_nth_level_page
*
* Quick, small function to check if your page is currently the nth child
*
* @param int $n The page level you want to check for
* @param int $page_id (optional) The ID of the page to check
*
* @return boolean
@Vyygir
Vyygir / class-theme-wc-walker.php
Last active September 19, 2017 11:06
Show WooCommerce basket total in wp_nav_menu item
<?php
/**
* A walker class for specific navigation menus in your theme, where you'd like to be
* able to show your WooCommerce basket total
*
* @package YOUR_THEME
* @since 1.0.0
*/
if (!class_exists('Theme_WC_Nav_Menu')) {
class Theme_WC_Nav_Menu extends Walker_Nav_Menu {
@Vyygir
Vyygir / customised-wp-oembed-services.php
Created December 15, 2017 11:15
Customise oembed fetching to pass arguments through to an alternate service
<?php
/**
* Customise oembed fetching to pass arguments through to alternate services
*/
add_filter('oembed_fetch_url', function($provider, $url, $args) {
if (strpos($provider, 'vimeo.com') !== false) {
if (isset($args['autoplay'])) {
$provider = add_query_arg('autoplay', absint($args['autoplay']), $provider);
}
@Vyygir
Vyygir / limit-wp-seo-breadcrumb-words.php
Created April 20, 2018 10:33
Limit the number of words used in bread "crumbs" in Yoast SEO
<?php
/**
* Limit the number of words output in a Yoast SEO bread "crumb"
*
* @param array $crumb The current "crumb" URL and text
*
* @return array
*/
add_filter('wpseo_breadcrumb_single_link_info', function($crumb) {
$word_limit = 3;