Skip to content

Instantly share code, notes, and snippets.

View benklocek's full-sized avatar

Ben Klocek benklocek

View GitHub Profile
@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' ) );
@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: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: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:4068706
Created November 13, 2012 22:00
Wordpress Config: Limit post revisions
/* limit number of post revisions */
define('WP_POST_REVISIONS', 5);
@benklocek
benklocek / WordPress Config: Local to remote Constant Definition
Last active January 12, 2016 20:06
Wordpress Config: Local to remote Constant definition
define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] );
define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] );
define( 'WP_CONTENT_URL', 'http://' . $_SERVER['HTTP_HOST'] . '/wp-content' );
@benklocek
benklocek / gist:4062520
Created November 12, 2012 22:39
Wordpress Functions: Custom Login Logo
// custom admin login logo for child theme * Don't forget /img/custom-login-logo.png :)
function bracia_custom_login_logo() {
echo '<style type="text/css">
h1 a { background-image: url('.get_bloginfo('stylesheet_directory').'/img/custom-login-logo.png) !important; }
</style>';
}
add_action('login_head', 'bracia_custom_login_logo', 11);
@benklocek
benklocek / gist:4062506
Created November 12, 2012 22:36
Wordpress Functions: Woo Site Copyright Override
//Override woocanvas copyright message on left footer
function bracia_woo_shortcode_site_copyright() {
return $output = sprintf( '%1$s%3$s %4$s %5$s%6$s %2$s', $atts['before'], $atts['after'], "&copy; " . date( 'Y' ), get_bloginfo( 'name' ) . '. <a href="/terms-conditions/">', __( 'All Rights Reserved', 'woothemes' ), '</a>.' );
}
add_filter('woo_shortcode_site_copyright', 'bracia_woo_shortcode_site_copyright', 2);
@benklocek
benklocek / gist:4062489
Created November 12, 2012 22:34
Wordpress Functions: Adjust JPEG filter quality
//set image quality higher
function filter_image_quality() { return 100; }
add_filter('wp_editor_set_quality','filter_image_quality');
@benklocek
benklocek / gist:4062466
Created November 12, 2012 22:32
Wordpress Functions: CSS Selector for Page as parent of custom post type
//current page filter to shop section
function bracia_add_class_to_wp_nav_menu($classes){
switch (get_post_type()){
case 'course':
// we're viewing a custom post type, so remove the 'current_page_xxx and current-menu-item' from all menu items.
$classes = array_filter($classes, "bracia_remove_parent_classes");
// add the current page class to a specific menu item (replace ###).
if (in_array('menu-item-44', $classes)){
$classes[] = 'current_page_parent';