Skip to content

Instantly share code, notes, and snippets.

View gschoppe's full-sized avatar

Greg Schoppe gschoppe

View GitHub Profile
@gschoppe
gschoppe / multibox_display_box_dimensions.php
Last active September 20, 2018 13:10
This function will return formatted HTML to display box dimensions and weights for multibox and non-multibox products
<?php
function get_multibox_dimension_output( $product_id = false ) {
$product = wc_get_product( $product_id );
if( !$product ) {
return;
}
$output = '';
$boxes = get_post_meta( $product->ID, '_wc-multibox-additional-boxes', true );
@gschoppe
gschoppe / functions.php
Created August 21, 2018 22:54
Add Featured Image Tag to Timber
<?php
/* populates the twig tag {{ featured_image_tag }} */
add_filter('timber_context', function( $context ){
$context['featured_image_tag'] = get_the_post_thumbnail( null, 'full' );
return $context;
});
@gschoppe
gschoppe / wp-jslabify-titles.php
Last active March 22, 2018 14:28
add to functions.php to allow WP jSlabify to slab post titles
<?php
add_filter( 'the_title', 'wp_jslabify_title', 10, 2 );
function wp_jslabify_title( $title, $id=0 ) {
$slabbed_post_types = array(
'single' => array( 'post', 'page' ),
'archive' => array(),
'search' => array()
);
$theme = 'ultra';
@gschoppe
gschoppe / upcoming-drafts-alert.php
Created December 22, 2017 15:31
Sends regular reminder emails to all users with draft posts scheduled for less than X days in the future. Usage: 1. Install and activate WP Utility Script Runner (https://wordpress.org/plugins/wp-utility-script-runner/) 2. Create a "utilities" subfolder in your theme directory 3. Place this file in the utilities folder 4. Go to Tools->Utility Sc…
<?php if(!defined('ABSPATH')) { die(); } // This line ensures that the script is not run directly
/**
* Utility Name: Upcoming Drafts Alert
* Description: Sends an email to blog authors with upcoming or overdue posts
* Author: Greg Schoppe
* Author URI: https://gschoppe.com
* Supports: input, cron
* Version: 1.0.0
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
@gschoppe
gschoppe / mb_string_shim.php
Last active November 16, 2017 00:58
Shim for servers that do not support mb_string functions. modified from Patchwork. Usage: if(!function_exists('mb_strtolower')) { require_once('mb_string_shim.php'); }
<?php
/*
* Copyright (C) 2013 Nicolas Grekas - p@tchwork.com
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the (at your option):
* Apache License v2.0 (http://apache.org/licenses/LICENSE-2.0.txt), or
* GNU General Public License v2.0 (http://gnu.org/licenses/gpl-2.0.txt).
*/
<?php
function populate_cpt_labels( $singular, $plural, $overrides = array(), $text_domain = "" ) {
return shortcode_atts( array(
'name' => _x( $plural, 'Post Type General Name', $text_domain ),
'singular_name' => _x( $singular, 'Post Type Singular Name', $text_domain ),
'menu_name' => __( $plural, $text_domain ),
'name_admin_bar' => __( $singular, $text_domain ),
'archives' => __( $singular . ' Archives', $text_domain ),
'attributes' => __( $singular . ' Attributes', $text_domain ),
'parent_item_colon' => __( 'Parent ' . $singular . ':', $text_domain ),
<?php
$product_id = 147; // This is just for demonstration, you would use whatever product ID the page is referencing. if the page is the product page itself, you can use get_the_ID();
// we output a different version of the button, depending on whether the item is in the cart already
// note the class on the button... we are using that class to target our javascript handler
// note the data-attribute, that's how the product ID gets to our AJAX handler
if( !my_custom_cart_contains( $product_id ) ) {
?>
<button class="my-custom-add-to-cart-button" data-product-id="<?php echo $product_id; ?>">add to cart</button>
<?php
@gschoppe
gschoppe / better_auto_excerpts.php
Last active February 12, 2017 00:57
Micro-Plugin to improve auto excerpts generated from the_content. Can be placed in plugins, integrated in other projects, or called with an include statement in functions.php
<?php if(!defined('ABSPATH')) { die(); } // Include in all php files, to prevent direct execution
/**
* Plugin Name: Better Auto Excerpts
* Plugin URI:
* Description: replaces block-level elements with whitespace, to improve the_excerpt
* Version: 1.0.0
* Author: Burlington Bytes
* Author URI: https://www.burlingtonbytes.com
* Text Domain: better-auto-excerpts
* License: GPL-2.0+
@gschoppe
gschoppe / commentify_shortcodes.php
Last active January 23, 2017 02:57
Hide shortcodes if rendering fails in WordPress 4.7+
<?php
/*
* Hide shortcodes in excerpts or if rendering fails
* Usage: <!--[shortcode-name comment-wrapped=true]-->
*/
add_filter( 'do_shortcode_tag', "comment_wrap_shortcodes", 10, 3 );
function comment_wrap_shortcodes( $output, $tag, $atts ) {
$args = shortcode_atts( array(
'comment-wrapped' => 'false'
), $atts );
@gschoppe
gschoppe / blockade_theme_setup.php
Created January 7, 2017 15:34
Customize Blockade for your theme
<?php /* place in functions.php */
add_action( 'after_setup_theme', 'my_theme_setup' );
function my_theme_setup() {
add_editor_style(); // We recommend using an editor-style.css file , that includes all the styles that will apply to the content
add_theme_support( 'wp-blockade' ); // This tells Blockade that your theme includes Bootstrap
// add_theme_support( 'bootstrap', '3.3.7' ); // alternatively, you can just register bootstrap support, along with your version number
$palette = array( // set the colors available in the editor's colorpickers
'Primary' => '#811381',
'Black' => '#000000',
'White' => '#FFFFFF',