Skip to content

Instantly share code, notes, and snippets.

View leonkorteweg's full-sized avatar

Leon Korteweg leonkorteweg

View GitHub Profile
@leonkorteweg
leonkorteweg / responsive-youtube-nocookie.php
Last active April 17, 2018 16:09
Responsive YouTube embed without cookies (WordPress snippet)
<?php
/**
* Responsive YouTube embed without cookies (WordPress snippet)
*
* Usage: Add this shortcode to your page to embed a video: [video id="{{your youtube id here}}"]
* Installation: Add this snippet in the functions.php file of your plugin or via the Code Snippets plugin
*/
add_shortcode( 'video' , 'hayona_shortcode_youtube_nocookie' );
function hayona_shortcode_youtube_nocookie( $atts ) {
@leonkorteweg
leonkorteweg / var.js
Last active September 7, 2018 20:08
Google Tag Manager Variable: Click classes incl. parent elements
/**
* Click classes incl. parent elements
*
* @return {string} containing all classnames of the click element and two parent elements
* @description: Use the following code in a custom JavaScript macro variable in Google Tag Manager
*/
function() {
classNames = "";
el = {{Click Element}};
@leonkorteweg
leonkorteweg / static.php
Last active August 3, 2016 10:12
Static methods in PHP
<?php
class Test {
public static function formatMessage($message){
return $message . '!!!';
}
public static function displayMessage($message) {
return self::formatMessage($message);
@leonkorteweg
leonkorteweg / .htaccess
Last active July 14, 2016 08:11
common .htaccess redirects
# HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://www.yoursite.com/$1 [R=301,L]
# HTTPS to HTTP
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteRule ^(.*) http://www.yoursite.com/$1 [R=301,L]
@leonkorteweg
leonkorteweg / inheritance.js
Created July 14, 2016 05:20
Inheritance in JS
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Person.prototype.fullName = function() {
return this.firstName + " " + this.lastName;
};
function Teacher(roomNumber) {
@leonkorteweg
leonkorteweg / wp-hooked_functions.php
Created July 8, 2016 09:58
WordPress - display hooked functions
<?php
function hooked_functions( $name = "" ) {
global $wp_filter;
if( $name != "" )
var_export( $wp_filter[$name] );
else
var_export( $wp_filter );
}
@leonkorteweg
leonkorteweg / em-media-query.md
Last active March 21, 2016 12:49
EM units in media queries

Using EM units in media queries

Zell Liew did some research on em, px and rem units in media queries. In his article he shows that pixel units should not be used in media queries. Instead we should use em units. The main reason is that the pixel based values don't work properly in Safari. When a user increases the font size of the page, the pixel based media queries don't scale accordingly.

Converting pixel units to em in media queries

Here is an example media query with pixel units:

@media only screen and (min-width: 800px) { … }
@leonkorteweg
leonkorteweg / .bashrc
Created January 26, 2016 15:36
Install WordPress via commandline alias
alias wpinstall="wget http://wordpress.org/latest.tar.gz && tar xfz latest.tar.gz && mv wordpress/* ./ && rmdir ./wordpress/ && rm -f latest.tar.gz && mv wp-config-sample.php wp-config.php && vim wp-config.php"
@leonkorteweg
leonkorteweg / Preferences.sublime-settings
Created January 12, 2016 09:04
Sublime Text - Preferences
{
"color_scheme": "Packages/Base16 Color Schemes/base16-default.light.tmTheme",
"font_size": 12,
"ignored_packages":
[
"Vintage"
],
"soda_classic_tabs": true,
"theme": "Soda Light 3.sublime-theme",
"folder_exclude_patterns": [".svn", ".git", ".hg", "CVS", ".sass-cache", ".codekit-cache"]
@leonkorteweg
leonkorteweg / sort_wp_loop.php
Last active December 4, 2015 09:12
Sort WordPress loop
<?php
function wiki_agency_sort( $query ) {
if ( $query->is_post_type_archive( 'reisbureaus' ) && $query->is_main_query() ) {
$query->set( 'orderby', array('title' => 'ASC') );
}
}
add_action( 'pre_get_posts', 'wiki_agency_sort' );