Skip to content

Instantly share code, notes, and snippets.

View benklocek's full-sized avatar

Ben Klocek benklocek

View GitHub Profile
@benklocek
benklocek / gist:4092006
Created November 16, 2012 23:52
WordPress Functions: Simple Shortcode
//[foobar]
function foobar_func( $atts ){
return "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );
@benklocek
benklocek / gist:4166020
Created November 29, 2012 01:07
WordPress Template: ACF Image URL
<?php
$img_ID = get_field( '_image', $featured->ID );
$img = wp_get_attachment_image_src( $img_ID, 'course-featured' ); ?>
<span style="background-image: url( <?php echo $img[0]; ?> );">&nbsp;</span>
@benklocek
benklocek / gist:4496316
Created January 9, 2013 19:59
WordPress .htaccess: Load image from Live if not on dev
# Attempt to load files from production if they're not in our local version
# Adapted from: http://stevegrunwell.com/blog/keeping-wordpress-under-version-control-with-git
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^assets/(.*\.(gif|jpg|png)) http://site.com/assets/$1 [L,R]
</IfModule>
@benklocek
benklocek / gist:5043144
Last active December 14, 2015 06:29 — forked from billerickson/gist:1847185
WP oEmbed from URL
$video = wp_oembed_get( esc_url( get_post_meta( $post->ID, 'be_video_url', true ) ), array( 'width' => '270' ) );
<?php
//Goal to merge $user['CustomFields'] with $customfields.
//fields from API
$customfields[] = (object) array('Key' => 'Email Lists', 'Value' => 'Events');
$customfields[] = (object) array('Key' => 'Office Affiliation', 'Value' => 'Oxford');
$customfields[] = (object) array('Key' => 'Office Affiliation', 'Value' => 'San Francisco');
//fields from form
<?php
$array_name[0] = 'Keith Pelczarski';
$array_name[1] = 'Heather Harding';
$array_bio[0] = 'keith bio';
$array_bio[1] = 'heather bio';
$array_photo[0] = 'url/to/imag.jpg';
@benklocek
benklocek / post-update
Last active December 16, 2015 22:09
Git Hub repo post-update hook to update based on branch pushed. modified from http://blog.ekynoxe.com/2011/10/22/git-post-receive-for-multiple-remote-branches-and-work-trees/
#!/bin/bash
#
# post-update hook for Hub git repo
# http://stackoverflow.com/questions/5753346/git-automatically-push-to-dev-and-production-from-central-repository-depending-o?rq=1
# post-update only receives refname
# TODO: adjust for post-update ref, and cd to Prime and pull
#
livepath="/path/to/your/live"
devpath="/path/to/your/dev"
while read oldrev newrev ref
@benklocek
benklocek / html5-boilerplate-htaccess-simple
Created May 3, 2013 22:34
html5-boilerplate-htaccess-simple
# ##############################################################################
# # INTERNET EXPLORER #
# ##############################################################################
# ------------------------------------------------------------------------------
# | Better website experience |
# ------------------------------------------------------------------------------
# Force IE to render pages in the highest available mode in the various
# cases when it may not: http://hsivonen.iki.fi/doctype/ie-mode.pdf.
@benklocek
benklocek / gist:5759467
Created June 11, 2013 18:34
Force wrap long lines CSS
white-space: pre-line; /* CSS 3.0 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: -moz-pre-wrap; /* Mozilla */
white-space: -hp-pre-wrap; /* HP Printers */
word-wrap: break-word; /* IE 5+ */
@benklocek
benklocek / gist:7206060
Last active November 14, 2018 15:35
Wordpress Functions: Bust cache, register and enqueue stylesheet
<?php
// cache bust, register, and enqueue main stylesheet
$cache_bust = '?'.filemtime( get_stylesheet_directory() . '/css/style.css');
wp_register_style( 'main-stylesheet', get_stylesheet_directory_uri() . '/css/style.css'.$cache_bust, array(), '', 'all' );
wp_enqueue_style( 'main-stylesheet' );