Skip to content

Instantly share code, notes, and snippets.

View davidvandenbor's full-sized avatar

David van den Bor davidvandenbor

View GitHub Profile
@davidvandenbor
davidvandenbor / contact_7_prevent_loader.php
Last active August 29, 2015 14:03
WordPress: Prevent Contact 7 javascript and stylesheets from loading on EVERY page
<?php
/**
* Prevent Contact Form 7 javascript and styles from loading on every page
* Load them only on pages that contain the CF7 shortcode!
* @author @david <david@davidvandenbor.nl>
*/
function david_dequeue_scripts() {
$load_scripts = false;
if( is_singular() ) {
@davidvandenbor
davidvandenbor / basic_wp_seo.php
Created July 8, 2014 02:01
WordPress: Basic SEO
<?php
/* Basic WP SEO
Usage:
1. add this code to functions.php
2. replace the $default_keywords with your own
3. add <?php echo basic_wp_seo(); ?> to header.php
4. test well and fine tune as needed
Optional: add custom description, keywords, and/or title
to any post or page using these custom field keys:
@davidvandenbor
davidvandenbor / single.php
Last active August 29, 2015 14:03
WordPress: Metabox example
<?php
/** The standard call to display all meta data.
* The function returns HTML code. Fields are shown in a list.
* <ul class='post-meta'>
* <li><span class='post-meta-key'>Meta Key</span> Value</li>
* </ul>
*/
the_meta(); ?>
<?php
@davidvandenbor
davidvandenbor / handy.htaccess
Created July 8, 2014 12:48
Handy .htaccess entries
# hide index.php from the domain URL
# for WordPress users: Permalink URL canonicalization is automated via PHP in WordPress 2.3+
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# parked domains permanent 301 redirect so search engines not to treat them as duplicate content.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.maindomain.com$
RewriteRule ^(.*)$ http://www.maindomain.com/$1 [R=301]
@davidvandenbor
davidvandenbor / wp_config.php
Last active August 29, 2015 14:03
WordPress: Limit post revisions
<?php
// Limit the number of revisions that posts and pages can make
// Put this in your wp_config.php
define( 'WP_POST_REVISIONS', 1 );
// to disable all revisions except the autosave
define('WP_POST_REVISIONS', false);
?>
@davidvandenbor
davidvandenbor / enqueue_google_fonts.php
Last active September 22, 2015 13:18
Enqueue Google Fonts
<?php
/**
* Enqueue Googl Fonts
* @author @david
*/
function google_fonts() {
$query_args = array(
'family' => 'Open+Sans:400,700|Oswald:700',
'subset' => 'latin,latin-ext'
@davidvandenbor
davidvandenbor / query_posts_rewind_posts.php
Created July 31, 2014 21:08
Multiple query_posts with rewinds
<?php
// WARNING: query_posts() will change your main query and is not recommended
// for secondary loops! Only use if absolutely necessary!!!!
// Creating a new instance of WP_Query or get_posts() is preferred for secondary loops.
// Check lines 10 and 22:
// Line 1 is telling WordPress to only display 1 post,
// which will automatically be the most recent one.
// On Line 22 we are telling WordPress to offset the posts by 1,
// which means it will not repeat the post output in the first loop.
@davidvandenbor
davidvandenbor / responsive_grid_fluid.html
Last active August 29, 2015 14:05
simple responsive grid with CSS flex
<!DOCTYPE html>
<html lang="en">
<head>
<title>Responsive Web Design Pattern: Mostly Fluid</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="cleartype" content="on">
<link rel="stylesheet" href="/web/fundamentals/resources/samples/css/normalize.css">
@davidvandenbor
davidvandenbor / jquery_hover_for_tablets.html
Created September 5, 2014 15:39
JQuery hover for tablets or smartphones
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
<script>
$('a.taphover').on("touchstart", function (e) {
@davidvandenbor
davidvandenbor / _layout.scss
Last active August 29, 2015 14:06
SASS: Replace Foundation grid classes with semantic classes
@import "foundation/components/grid";
.layout {
// `layout` container functions as a row
@include grid-row();
}
.layout-content {
// Mobile-first: make `layout-container` full-width
@include grid-column(12);