Skip to content

Instantly share code, notes, and snippets.

View bepatrickdavid's full-sized avatar

bepatrickdavid bepatrickdavid

View GitHub Profile
$(function() {
$("#findstore").bind("keydown", function(e) {
if (e.keyCode == 13) {
return false;
}
});
});
@bepatrickdavid
bepatrickdavid / gist:8d0f8e4994d2e0a72d1dc3150f01ef06
Created August 12, 2016 14:25
PHP: Foreach with key / index
foreach($array as $key => $item){
echo $key . ":" . $item . "<br>";
}
@bepatrickdavid
bepatrickdavid / .htaccess
Created September 21, 2016 09:15
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@bepatrickdavid
bepatrickdavid / gist:de2991f0a116beaaefdeae349f91d41a
Created October 6, 2016 07:44
WPML: preserve url parameters
https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/
in the wpml settings insert parameters
var images = ['<?=implode("', '", $cachedImages)?>'];
@bepatrickdavid
bepatrickdavid / cacheimages.js
Created October 7, 2016 09:52
JS: Preload images after all page is load
function preloadImages(array) {
if (!preloadImages.list) {
preloadImages.list = [];
}
var list = preloadImages.list;
for (var i = 0; i < array.length; i++) {
var img = new Image();
img.onload = function() {
var index = list.indexOf(this);
if (index !== -1) {
@bepatrickdavid
bepatrickdavid / .htaccess
Created November 11, 2016 10:36
.htaccess: Rewrite .html file extensions with htaccess ex.redirect from /blog.html to /blog too. No duplicate pages for SEO
# This tag ensures the rewrite module is loaded
<IfModule mod_rewrite.c>
# enable the rewrite engine
RewriteEngine On
# Set your root directory
RewriteBase /
# remove the .html extension
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
RewriteRule (.*)\.html$ $1 [R=301]
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="noodp, noydir" />
<link rel="dns-prefetch" href="//cdnjs.cloudflare.com">
<link rel="canonical" href="http://mysite.com/" />
<link rel="stylesheet" href="http://mysite.com/style.css" type="text/css" />
@bepatrickdavid
bepatrickdavid / functions.php
Created March 7, 2017 10:26
WPML: Widget translation
function widget( $args, $instance ) {
extract($args);
$title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance );
}
@bepatrickdavid
bepatrickdavid / style.css
Last active December 6, 2018 14:27
[CSS] class style
[class$="test"]
elements that have a class that ends with “test”
[class*=“test"]
elements that have a class that contain “test”
[class~=“test”]
elements that have a class that contain at least class“test”
[class|=“test”]