Skip to content

Instantly share code, notes, and snippets.

@retlehs
retlehs / gist:01477d70c01f50a87553
Created April 14, 2015 02:03
Enable test mode for Easy Digital Downloads if you're not on production
<?php
/**
* If not on production, enable test mode for Easy Digital Downloads
*/
add_action('edd_is_test_mode', function() {
return WP_ENV !== 'production';
});
@retlehs
retlehs / autoexec.cfg
Created January 7, 2012 22:57
ra3 autoexec.cfg
// f27-ben (benword.com)
// 01.07.2012
// quake3 ra3
cg_fov 106
cg_chatbeep 0
cg_simpleitems 1
cg_noProjectileTrail 1
cg_drawGun 0
cg_autoswitch 0
@retlehs
retlehs / gist:2703644
Created May 15, 2012 17:44
Add a class to widgets in a specific sidebar
<?php
/**
* Add 'class="span4"' to all widgets in the Content Bottom sidebar
*/
function bb_content_bottom_widget_class($params) {
if ($params[0]['id'] == 'roots-content-bottom') {
$class = 'class="span4 ';
$params[0]['before_widget'] = preg_replace('/class=\"/', "$class", $params[0]['before_widget'], 1);
}
@retlehs
retlehs / gist:2785401
Created May 25, 2012 02:17
Display YouTube thumbnail from embed URL
<?php
/**
* Display a thumbnail from YouTube based off the embed code saved in the
* video post format metabox used by the CF Post Formats plugin
*
* @link https://github.com/crowdfavorite/wp-post-formats
* @link http://stackoverflow.com/a/6382259
*/
global $post;
@retlehs
retlehs / gist:4120053
Created November 20, 2012 18:45
Remove unnecessary markup from WooCommerce
<?php
/**
* Remove unnecessary markup from WooCommerce:
*
* 1. Remove <meta name="generator" content="WooCommerce (version)" />
* 2. Remove the addition of <body class="theme-themename">
*/
function woocommerce_head_cleanup() {
global $woocommerce;
@retlehs
retlehs / gist:1023864
Created June 13, 2011 22:16
truncate WordPress titles (most simple solution)
<?php
/*
* wp_trim_words() was introduced with 3.3.0
*
* @link http://codex.wordpress.org/Function_Reference/wp_trim_words
*/
wp_trim_words(get_the_title());
@retlehs
retlehs / an-introduction-to-the-roots-theme-wrapper.md
Created February 26, 2015 15:04
Roots documentation from pre-8.0.0

After reading through this guide, you will:

  • Understand the Roots Wrapper and recognize how it extends and complements the WordPress template hierarchy.
  • Know what is meant by the DRY Principle, why being DRY bests being WET, and see how most WordPress themes are WET.
  • Be able to filter the Roots Wrapper and create a new base template for a Custom Post Type.

Template Hierarchy

WordPress is pretty smart. Every time you load up a request it will search for the most relevant template available in your theme and load it. This is the Template Hierarchy in action and it enables us to easily customize the appearance of our sites.

@retlehs
retlehs / gist:e5683cb8377e1b1836ab
Created May 26, 2015 16:26
Don't be scared of Sage

This is from a comment on the Advanced WordPress Facebook group by Kevin Hoffman.


Disclaimer: I'm not affiliated with Roots, just a satisfied user.

In response to several recent questions on the topic of starter themes, the following are my thoughts on what I believe is the best starter theme available today, along with a heads-up on an upcoming resource that may help you in the near future.

Recommendations for starter themes come up quite often in AWP, and my first instinct is to recommend Roots' Sage starter theme (https://roots.io/sage/), but to be honest, it's not for everyone. I feel like I always have to attach the caveat concerning the prerequisites: Node.js, gulp, Bower, CSS preprocessing, build processes, etc. I often see advanced devs discouraging others from trying Sage if they're not 100% up to date on all of these tools. Don't let that scare you.

@retlehs
retlehs / header.php
Created April 29, 2015 04:55
Sage header template for Bootstrap top navbar component
<?php
// This file assumes that you have included the nav walker from https://github.com/twittem/wp-bootstrap-navwalker
// somewhere in your theme.
?>
<header class="banner navbar navbar-default navbar-static-top" role="banner">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only"><?= __('Toggle navigation', 'sage'); ?></span>
@retlehs
retlehs / sync-prod.sh
Last active January 26, 2022 03:48
WP-CLI aliases sync example
read -r -p "Would you really like to reset your development database and pull the latest from production? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
wp @development db reset --yes &&
wp @production db export - > sql-dump-production.sql &&
wp @development db import sql-dump-production.sql &&
wp @development search-replace https://example.com https://example.dev
fi