Skip to content

Instantly share code, notes, and snippets.

View mrsize's full-sized avatar

Thomas Dufranne mrsize

View GitHub Profile
@dlucian
dlucian / Timezone-Select-Template.html
Created June 10, 2013 20:32
Timezone generated HTML output by the Timezone PHP Generator: https://github.com/dlucian/Timezone-Generator-PHP
<select name="timezone" id="timezone">
<optgroup label="UTC -11:00">
<option value="Pacific/Midway">UTC -11:00 Midway</option>
<option value="Pacific/Niue">UTC -11:00 Niue</option>
<option value="Pacific/Pago_Pago">UTC -11:00 Pago_Pago</option>
</optgroup>
<optgroup label="UTC -10:00">
<option value="America/Adak">UTC -10:00 Adak</option>
<option value="Pacific/Honolulu">UTC -10:00 Honolulu</option>
<option value="Pacific/Johnston">UTC -10:00 Johnston</option>
@james2doyle
james2doyle / slugify.php
Last active January 12, 2022 13:19
Simple slugify function for PHP. Creates a slug for the passed string, taking into account international characters as well.
<?php
function slugify($string, $replace = array(), $delimiter = '-') {
// https://github.com/phalcon/incubator/blob/master/Library/Phalcon/Utils/Slug.php
if (!extension_loaded('iconv')) {
throw new Exception('iconv module not loaded');
}
// Save the old locale and set the new locale to UTF-8
$oldLocale = setlocale(LC_ALL, '0');
setlocale(LC_ALL, 'en_US.UTF-8');
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
@luckyshot
luckyshot / readability.css
Last active May 8, 2017 19:50
Typography readability optimization & weight info
/*
100 = thin
200 = extra-light
300 = light
400 = normal, book
500 = medium
600 = demi-bold
700 = bold
800 = heavy
900 = black
@Clorith
Clorith / functions.php
Last active April 9, 2024 01:35
WordPress filter for adding responsive wrapper to embedded content
<?php
/**
* Filter for adding wrappers around embedded objects
*/
function responsive_embeds( $content ) {
$content = preg_replace( "/<object/Si", '<div class="embed-container"><object', $content );
$content = preg_replace( "/<\/object>/Si", '</object></div>', $content );
/**
* Added iframe filtering, iframes are bad.
@sareiodata
sareiodata / empty-wp-plugin.php
Created July 2, 2014 08:45
Empty WordPress plugin
<?php
/**
* Plugin Name: Name Of The Plugin
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: A brief description of the Plugin.
* Version: The Plugin's Version Number, e.g.: 1.0
* Author: Name Of The Plugin Author
* Author URI: http://URI_Of_The_Plugin_Author
* License: A "Slug" license name e.g. GPL2
*/
@schilke
schilke / functions.php
Last active February 23, 2023 18:53
How to load CSS files asynchronously in WordPress (using Scott Jehl's "loadCSS")
<?php
// This is the cleaner code per request of a thread in the LinkedIn group "WordPress"
// ...
// register and enqueue loadCSS
function load_scripts_and_styles() {
// register loadCSS
wp_register_script( 'load-css-async', get_stylesheet_directory_uri() . '/path/to/js/loadCSS.js', array(), '', false );
@luckyshot
luckyshot / geoip.php
Last active November 13, 2020 17:58
PHP - Geolocalization by IP address
<?php
define('GEOIP_CACHE_TIME', 5184000); // 5184000 = 60 days
/**
* Returns the country of an IP address
* If IP is cached and less than 2 months old, otherwhise requests it to geoplugin.com API
*
* @string $ip The IP address
* @bool $justcountry If you want the full array or just the country
@tomazzaman
tomazzaman / functions.php
Created February 18, 2015 23:57
Insert image in WordPress with HTML5 <figure> tag and caption
<?php
// Don't include the opening tag
function html5_insert_image( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
$src = wp_get_attachment_image_src( $id, $size, false );
$html5 = "<figure id=\"post-$id media-$id\" class=\"align-$align\">";
if ( $url ) {
$html5 .= "<a href=\"$url\" class=\"image-link\"><img src=\"$src[0]\" alt=\"$alt\" /></a>";
} else {
@birgire
birgire / woo-product-attributes-bulk-modifier.php
Last active April 26, 2025 07:35
WordPress: WooCommerce Product Attributes - Bulk Modifier ( from custom meta attributes to taxonomy attributes)
<?php
/**
* Plugin Name: WooPAM: Woo Product Attributes Modifier
* Description: Bulk update 'custom meta product attributes' to 'taxonomy product attributes' in WooCommerce. Supports the GET variables, like: woopam_mode=run&woopam_from_attribute_meta=colour&woopam_to_attribute_tax=pa_colour&woopam_keep_attribute_meta&woopam_posts_per_page=10&woopam_paged=0&woopam_post_type=product&woopam_post_status=any. WARNING: Backup DB first!!!
* Plugin Author: birgire
* Author URI: https://github.com/birgire
* Plugin URI: https://gist.github.com/birgire/0ed300ae4436fcaf508c
* Version: 1.0.0
* License: GPL2+
* Text Domain: woopam
@luckyshot
luckyshot / multilanguage.php
Created June 1, 2015 20:57
Simple Multilanguage functionality
<?php
define('LANGUAGES_PATH', 'languages/');
define('DEFAULT_LANGUAGE', 'en');
define('LANGUAGE_COOKIE_TIME', 1314000 ); // 3600 * 365 = 1314000; (1 year)
define('COOKIE_DOMAIN', '.xaviesteve.com');
/*
Usage: