Skip to content

Instantly share code, notes, and snippets.

Matt Royce Vyygir

Block or report user

Report or block Vyygir

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Vyygir
Vyygir / limit-wp-seo-breadcrumb-words.php
Created Apr 20, 2018
Limit the number of words used in bread "crumbs" in Yoast SEO
View limit-wp-seo-breadcrumb-words.php
<?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;
@Vyygir
Vyygir / customised-wp-oembed-services.php
Created Dec 15, 2017
Customise oembed fetching to pass arguments through to an alternate service
View customised-wp-oembed-services.php
<?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 / class-theme-wc-walker.php
Last active Sep 19, 2017
Show WooCommerce basket total in wp_nav_menu item
View class-theme-wc-walker.php
<?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 / is_nth_level_page.php
Created Feb 20, 2017
Quick, small function to check if your page is currently the nth child
View is_nth_level_page.php
<?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 / time_elapsed_string.php
Last active Feb 10, 2017 — forked from zachstronaut/gist:1184831
Get a relative time string in PHP without a lot of if/else or switch/case
View time_elapsed_string.php
<?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 / custom-tax-dropdown.php
Last active Feb 24, 2017
[WP] Custom taxonomy dropdown menu
View custom-tax-dropdown.php
<?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 / [WP] Force download headers
Last active Jan 31, 2017
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
View [WP] Force download headers
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 / .gitignore
Created Aug 9, 2016
.gitignore for working environment (rough draft)
View .gitignore
### OS X ###
*.DS_Store
.AppleDouble
.LSOverride
Icon
._*
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
@Vyygir
Vyygir / preload.js
Last active Apr 12, 2016
Relatively simple image preloader
View preload.js
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 / sharing-links.php
Last active Feb 7, 2016
Post Sharing for Programmers original class before plugin creation
View sharing-links.php
You can’t perform that action at this time.