Skip to content

Instantly share code, notes, and snippets.

@reanim8ed
reanim8ed / sample.php
Last active August 29, 2019 21:09
[Extract youtube video ID from url] #php
<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)
// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ
// http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/0/dQw4w9WgXcQ
@reanim8ed
reanim8ed / functions.php
Last active February 8, 2020 08:27
[Add checkbox field to the checkout] #woocommerce
/**
* Add checkbox field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my-new-field"><h3>'.__('My Checkbox: ').'</h3>';
woocommerce_form_field( 'my_checkbox', array(
@reanim8ed
reanim8ed / .htaccess
Last active February 8, 2020 08:25
[Localhost links not working] #htaccess
Options +FollowSymLinks
@reanim8ed
reanim8ed / .htaccess
Last active February 8, 2020 08:25
[Redirect bad bots] #htaccess #SEO #redirects
RewriteEngine On
RewriteCond %{REQUEST_URI} !/robots.txt$
RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^.*EventMachine.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*NerdyBot.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*Typhoeus.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*archive.org_bot.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*archive.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*github.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*chroot.*$ [NC,OR]
@reanim8ed
reanim8ed / .htaccess
Last active February 8, 2020 08:24
[Redirect www to non www] #htaccess #redirects
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
@reanim8ed
reanim8ed / sample.html
Created August 29, 2019 21:21
[Video element play on mobile] #html5 #video #mobile
<video width="100%" autoplay="autoplay" loop="loop" autobuffer="autobuffer" muted="muted" playsinline="playsinline">
<source data-src="./images/vid.mp4" type="video/mp4" />
</video>
@reanim8ed
reanim8ed / sample.html
Last active February 8, 2020 08:21
[Picture tag] Use multiple image formats with a fallback #html5 #webp
<picture>
<source srcset='your/path/image.webp' type='image/webp' />
<img src='your/path/image.jpg' alt="" />
</picture>
@reanim8ed
reanim8ed / sample.php
Created August 29, 2019 21:26
[Prestashop - remove default lang from url] #prestashop
class Link extends LinkCore
{
protected function getLangLink($id_lang = null, Context $context = null, $id_shop = null)
{
$parent_result = parent::getLangLink($id_lang, $context, $id_shop);
if ($parent_result) {
if ($id_lang == Configuration::get('PS_LANG_DEFAULT')) {
return '';
} else {
@reanim8ed
reanim8ed / sample.php
Last active February 8, 2020 08:13
[Capital first in string with UTF support] #php
<?php
function mb_ucfirst($string){
return mb_strtoupper(mb_substr($string, 0, 1)).mb_strtolower(mb_substr($string, 1));
}
@reanim8ed
reanim8ed / sample.php
Last active August 29, 2019 21:40
[Auto sync ACF json] #wordpress #ACF
//Auto sync from loaded JSON
function sync_acf_fields() {
$groups = acf_get_field_groups();
$sync = array();
// bail early if no field groups
if( empty( $groups ) )
return;