Custom Taxonomy and Custom Post Type Rewrites
When creating Custom Taxonomies and Custom Post types with rewrite rules in WordPress, the order in which they are registered matters. With the taxonomy registered first, WordPress will be able to work it’s magic for the rewrite rules to work.
// TAXONOMY FIRST
$tax_args = array(
'labels' => 'TAX_NAME',
'rewrite' => array( 'slug' => 'CPT/TAX/' )
);
register_taxonomy( 'CUSTOM_TAX_TYPE', 'CUSTOM_POST_TYPE', $tax_args );
// POST TYPE SECOND
$cpt_args = array(
'labels' => 'CPT_NAME',
'rewrite => ' array( 'slug' => 'CPT' )
);
register_post_type( 'CUSTOM_POST_TYPE', $cpt_args );
Published on June 13, 2017
Method to crop YouTube thumbnails to 16:9 with CSS only
I have a site displaying mixed thumbnail images based on content created by the client consisting of either a featured image (sized via WordPress), YouTube thumbnails or a proxy image (static size). The featured image and proxy images are 16:9 sized images so there’s no problem there. YouTube thumbnail images, specifically hqdefault, are sized as 4:3 thus ruining the grid layout on the page I have all this content eventually displaying on. I wanted to find a low bandwidth solution to crop the YouTube thumbnails since the site was already looking to be on the heavy end. Without further adieu, my solution:
hqdefault = 4:3 = 0.75 = 75% // pre-crop images
16:9 = 0.5625 = 56.25% // cropped images
75% - 56.25% = 18.75% // difference in size
Now we take that difference in size, divide it in half and add that to the image as negative margins. Which creates our “crop”
18.75% / 2 = 9.375%
// HTML <figure> <img src="https://img.youtube.com/vi/YOUR_VIDEO_ID/hqdefault.jpg" alt=""> </figure>
// SCSS
figure {
overflow:hidden;
img {
margin:-9.375% 0;
display:block;
width:100%;
height:auto;
}
}
Codepen example.
Published on February 17, 2017Convert two letter country code to long name with PHP
This was useful today.
function countryCodeToName($code) {
switch ($code) {
case 'AF': return 'Afghanistan';
case 'AX': return 'Aland Islands';
case 'AL': return 'Albania';
case 'DZ': return 'Algeria';
case 'AS': return 'American Samoa';
case 'AD': return 'Andorra';
case 'AO': return 'Angola';
case 'AI': return 'Anguilla';
case 'AQ': return 'Antarctica';
case 'AG': return 'Antigua and Barbuda';
case 'AR': return 'Argentina';
case 'AM': return 'Armenia';
case 'AW': return 'Aruba';
case 'AU': return 'Australia';
case 'AT': return 'Austria';
case 'AZ': return 'Azerbaijan';
case 'BS': return 'Bahamas the';
case 'BH': return 'Bahrain';
case 'BD': return 'Bangladesh';
case 'BB': return 'Barbados';
case 'BY': return 'Belarus';
case 'BE': return 'Belgium';
case 'BZ': return 'Belize';
case 'BJ': return 'Benin';
case 'BM': return 'Bermuda';
case 'BT': return 'Bhutan';
case 'BO': return 'Bolivia';
case 'BA': return 'Bosnia and Herzegovina';
case 'BW': return 'Botswana';
case 'BV': return 'Bouvet Island (Bouvetoya)';
case 'BR': return 'Brazil';
case 'IO': return 'British Indian Ocean Territory (Chagos Archipelago)';
case 'VG': return 'British Virgin Islands';
case 'BN': return 'Brunei Darussalam';
case 'BG': return 'Bulgaria';
case 'BF': return 'Burkina Faso';
case 'BI': return 'Burundi';
case 'KH': return 'Cambodia';
case 'CM': return 'Cameroon';
case 'CA': return 'Canada';
case 'CV': return 'Cape Verde';
case 'KY': return 'Cayman Islands';
case 'CF': return 'Central African Republic';
case 'TD': return 'Chad';
case 'CL': return 'Chile';
case 'CN': return 'China';
case 'CX': return 'Christmas Island';
case 'CC': return 'Cocos (Keeling) Islands';
case 'CO': return 'Colombia';
case 'KM': return 'Comoros the';
case 'CD': return 'Congo';
case 'CG': return 'Congo the';
case 'CK': return 'Cook Islands';
case 'CR': return 'Costa Rica';
case 'CI': return 'Cote d\'Ivoire';
case 'HR': return 'Croatia';
case 'CU': return 'Cuba';
case 'CY': return 'Cyprus';
case 'CZ': return 'Czech Republic';
case 'DK': return 'Denmark';
case 'DJ': return 'Djibouti';
case 'DM': return 'Dominica';
case 'DO': return 'Dominican Republic';
case 'EC': return 'Ecuador';
case 'EG': return 'Egypt';
case 'SV': return 'El Salvador';
case 'GQ': return 'Equatorial Guinea';
case 'ER': return 'Eritrea';
case 'EE': return 'Estonia';
case 'ET': return 'Ethiopia';
case 'FO': return 'Faroe Islands';
case 'FK': return 'Falkland Islands (Malvinas)';
case 'FJ': return 'Fiji the Fiji Islands';
case 'FI': return 'Finland';
case 'FR': return 'France, French Republic';
case 'GF': return 'French Guiana';
case 'PF': return 'French Polynesia';
case 'TF': return 'French Southern Territories';
case 'GA': return 'Gabon';
case 'GM': return 'Gambia the';
case 'GE': return 'Georgia';
case 'DE': return 'Germany';
case 'GH': return 'Ghana';
case 'GI': return 'Gibraltar';
case 'GR': return 'Greece';
case 'GL': return 'Greenland';
case 'GD': return 'Grenada';
case 'GP': return 'Guadeloupe';
case 'GU': return 'Guam';
case 'GT': return 'Guatemala';
case 'GG': return 'Guernsey';
case 'GN': return 'Guinea';
case 'GW': return 'Guinea-Bissau';
case 'GY': return 'Guyana';
case 'HT': return 'Haiti';
case 'HM': return 'Heard Island and McDonald Islands';
case 'VA': return 'Holy See (Vatican City State)';
case 'HN': return 'Honduras';
case 'HK': return 'Hong Kong';
case 'HU': return 'Hungary';
case 'IS': return 'Iceland';
case 'IN': return 'India';
case 'ID': return 'Indonesia';
case 'IR': return 'Iran';
case 'IQ': return 'Iraq';
case 'IE': return 'Ireland';
case 'IM': return 'Isle of Man';
case 'IL': return 'Israel';
case 'IT': return 'Italy';
case 'JM': return 'Jamaica';
case 'JP': return 'Japan';
case 'JE': return 'Jersey';
case 'JO': return 'Jordan';
case 'KZ': return 'Kazakhstan';
case 'KE': return 'Kenya';
case 'KI': return 'Kiribati';
case 'KP': return 'Korea';
case 'KR': return 'Korea';
case 'KW': return 'Kuwait';
case 'KG': return 'Kyrgyz Republic';
case 'LA': return 'Lao';
case 'LV': return 'Latvia';
case 'LB': return 'Lebanon';
case 'LS': return 'Lesotho';
case 'LR': return 'Liberia';
case 'LY': return 'Libyan Arab Jamahiriya';
case 'LI': return 'Liechtenstein';
case 'LT': return 'Lithuania';
case 'LU': return 'Luxembourg';
case 'MO': return 'Macao';
case 'MK': return 'Macedonia';
case 'MG': return 'Madagascar';
case 'MW': return 'Malawi';
case 'MY': return 'Malaysia';
case 'MV': return 'Maldives';
case 'ML': return 'Mali';
case 'MT': return 'Malta';
case 'MH': return 'Marshall Islands';
case 'MQ': return 'Martinique';
case 'MR': return 'Mauritania';
case 'MU': return 'Mauritius';
case 'YT': return 'Mayotte';
case 'MX': return 'Mexico';
case 'FM': return 'Micronesia';
case 'MD': return 'Moldova';
case 'MC': return 'Monaco';
case 'MN': return 'Mongolia';
case 'ME': return 'Montenegro';
case 'MS': return 'Montserrat';
case 'MA': return 'Morocco';
case 'MZ': return 'Mozambique';
case 'MM': return 'Myanmar';
case 'NA': return 'Namibia';
case 'NR': return 'Nauru';
case 'NP': return 'Nepal';
case 'AN': return 'Netherlands Antilles';
case 'NL': return 'Netherlands the';
case 'NC': return 'New Caledonia';
case 'NZ': return 'New Zealand';
case 'NI': return 'Nicaragua';
case 'NE': return 'Niger';
case 'NG': return 'Nigeria';
case 'NU': return 'Niue';
case 'NF': return 'Norfolk Island';
case 'MP': return 'Northern Mariana Islands';
case 'NO': return 'Norway';
case 'OM': return 'Oman';
case 'PK': return 'Pakistan';
case 'PW': return 'Palau';
case 'PS': return 'Palestinian Territory';
case 'PA': return 'Panama';
case 'PG': return 'Papua New Guinea';
case 'PY': return 'Paraguay';
case 'PE': return 'Peru';
case 'PH': return 'Philippines';
case 'PN': return 'Pitcairn Islands';
case 'PL': return 'Poland';
case 'PT': return 'Portugal, Portuguese Republic';
case 'PR': return 'Puerto Rico';
case 'QA': return 'Qatar';
case 'RE': return 'Reunion';
case 'RO': return 'Romania';
case 'RU': return 'Russian Federation';
case 'RW': return 'Rwanda';
case 'BL': return 'Saint Barthelemy';
case 'SH': return 'Saint Helena';
case 'KN': return 'Saint Kitts and Nevis';
case 'LC': return 'Saint Lucia';
case 'MF': return 'Saint Martin';
case 'PM': return 'Saint Pierre and Miquelon';
case 'VC': return 'Saint Vincent and the Grenadines';
case 'WS': return 'Samoa';
case 'SM': return 'San Marino';
case 'ST': return 'Sao Tome and Principe';
case 'SA': return 'Saudi Arabia';
case 'SN': return 'Senegal';
case 'RS': return 'Serbia';
case 'SC': return 'Seychelles';
case 'SL': return 'Sierra Leone';
case 'SG': return 'Singapore';
case 'SK': return 'Slovakia (Slovak Republic)';
case 'SI': return 'Slovenia';
case 'SB': return 'Solomon Islands';
case 'SO': return 'Somalia, Somali Republic';
case 'ZA': return 'South Africa';
case 'GS': return 'South Georgia and the South Sandwich Islands';
case 'ES': return 'Spain';
case 'LK': return 'Sri Lanka';
case 'SD': return 'Sudan';
case 'SR': return 'Suriname';
case 'SJ': return 'Svalbard & Jan Mayen Islands';
case 'SZ': return 'Swaziland';
case 'SE': return 'Sweden';
case 'CH': return 'Switzerland, Swiss Confederation';
case 'SY': return 'Syrian Arab Republic';
case 'TW': return 'Taiwan';
case 'TJ': return 'Tajikistan';
case 'TZ': return 'Tanzania';
case 'TH': return 'Thailand';
case 'TL': return 'Timor-Leste';
case 'TG': return 'Togo';
case 'TK': return 'Tokelau';
case 'TO': return 'Tonga';
case 'TT': return 'Trinidad and Tobago';
case 'TN': return 'Tunisia';
case 'TR': return 'Turkey';
case 'TM': return 'Turkmenistan';
case 'TC': return 'Turks and Caicos Islands';
case 'TV': return 'Tuvalu';
case 'UG': return 'Uganda';
case 'UA': return 'Ukraine';
case 'AE': return 'United Arab Emirates';
case 'GB': return 'United Kingdom';
case 'US': return 'United States of America';
case 'UM': return 'United States Minor Outlying Islands';
case 'VI': return 'United States Virgin Islands';
case 'UY': return 'Uruguay, Eastern Republic of';
case 'UZ': return 'Uzbekistan';
case 'VU': return 'Vanuatu';
case 'VE': return 'Venezuela';
case 'VN': return 'Vietnam';
case 'WF': return 'Wallis and Futuna';
case 'EH': return 'Western Sahara';
case 'YE': return 'Yemen';
case 'ZM': return 'Zambia';
case 'ZW': return 'Zimbabwe';
}
return false;
}
from post at xcode. thanks!
Published on February 3, 2017Drumpf
Published on January 4, 2017
2016 Top Listens
Straight from my last.fm profile.
- Iron Chic 300
- Sam Cooke 226
- Diarrhea Planet 225
- Nancy Pants 218
- Sunflower Bean 208
- Wilco 198
- De La Soul 183
- Band of Horses 169
- Beach Slang 164
- Kevin Morby 159
- Nice As Fuck 154
- Whitney 145
- Car Seat Headrest 142
- Built to Spill 131
- Parquet Courts 131
- Lord Huron 128
- The Growlers 125
- Yo La Tengo 125
- Allah-Las 124
- Saintseneca 124
- St. Paul & The Broken Bones 121
- Magic Potion 119
- Leon Bridges 116
- Beach Skulls 114
- TV Girl 107
- White Denim 105
- The Shrine 103
- DIIV 101
- Acid Dad 96
- Stephen Steinbrink 96
- Lucy Dacus 94
- Amber Arcades 93
- Katy Goodman & Greta Morgan 89
- Witching Waves 88
- Beyond The Wizards Sleeve 83
- Bill Baird 81
- Beach House 80
- Quarterbacks 79
- The Castillians 79
- Japanese Breakfast 78
- Eureka California 77
- The Amazing 77
- Murs 76
- Banner Pilot 75
- Anderson .Paak 74
- My Morning Jacket 74
- Nathaniel Rateliff & the Night Sweats 74
- Rob Crow’s Gloomy Place 74
- Boat 73
- Kurt Vile 72
CSS Fixes
Published on October 21, 2016
CSS FizzBuzz
Saw this recently on twitter and am placing it here for posterity’s sake.
<html>
<head>
<title>Fizz Buzz via CSS</title>
<style>
body {
counter-reset:n;
}
div:before {
counter-increment:n;
content: counter(n);
}
div:nth-child(3n):before {
content:"fizz";
}
div:nth-child(5n):before {
content:"buzz";
}
div:nth-child(3n):nth-child(5n):before {
content:"fizzbuzz";
}
</style>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
...
</body>
</html>
Published on October 21, 2016
Issue using Isotope with Sage / Bower
Console error message: Cannot read property 'Item' of undefined
Every time this happens I can’t remember where the solution (read: workaround) is. So I am putting this here so future me won’t have to waste as much time:
https://github.com/metafizzy/isotope/issues/879
Scroll down to comment by desandro on Dec 2, 2015
Published on October 13, 2016How to find your Instagram User ID after June API update
Open your Instagram Profile Page in Google Chrome
Open Dev Tools
In the Console at the prompt enter:
window._sharedData.entry_data.ProfilePage[0].user.id
Time conditional in PHP
Working on a WooCommerce project and there are products that are available daily until they sell out or until noon so they can be delivered. I use this function and pair it with the $product->is_in_stock() from the Woo WC_product class to provide conditional content in the template.
function wc_valid_time() {
// Straight PHP using DateTime class
// date_default_timezone_set('America/Chicago');
// $current_time = new DateTime();
// $current_time->setTimezone(new DateTimeZone('America/Chicago'));
// or, let WP do the lifting, as TimeZone is already set
$current_time = current_time("H:i");
$start_time = "00:01"; // 12:01 am
$cutoff_time = "12:00"; // 12:00 pm
$right_now = DateTime::createFromFormat('H:i', $current_time);
$time2 = DateTime::createFromFormat('H:i', $start_time);
$time3 = DateTime::createFromFormat('H:i', $cutoff_time);
if ($right_now > $time2 && $right_now < $time3):
return true;
else :
return false;
endif;
}
EDIT 6/3/16:
It became necessary to filter for day of week as well as time of day, so below is how I did that:
function wc_valid_day() {
// timezone is already set in WP control panel
// date_default_timezone_set('America/Chicago');
$current_day = current_time('D'); // day as three letter text
// $current_time = new DateTime();
// $current_time->setTimezone(new DateTimeZone('America/Chicago'));
$saturday = 'Sat';
$sunday = 'Sun';
$what_day = DateTime::createFromFormat('D', $current_day);
$date2 = DateTime::createFromFormat('D', $saturday);
$date3 = DateTime::createFromFormat('D', $sunday);
if ($what_day == $date2 || $what_day == $date3):
return false;
else :
return true;
endif;
}
Inside the loop on the template page for these products I use these two functions with the WooCommerce is_in_stock() function in a conditional to show the time/day appropriate markup.