Skip to content

Instantly share code, notes, and snippets.

Avatar

Derek Ashauer ashwebstudio

View GitHub Profile
@ashwebstudio
ashwebstudio / WordPress Maintenance Message
Last active December 16, 2015 16:28
Add to your theme's functions.php file. If you are logged in as an admin, it let's you view the site as normal.
View WordPress Maintenance Message
add_action('wp', 'coming_soon');
function coming_soon() {
if (current_user_can('manage_options')) return;
wp_die('We are quickly performing an upgrade to our site - should be back up shortly.');
}
View ACF Divisions
<?php
class acf_field_divisions extends acf_field
{
// vars
var $settings, // will hold info such as dir / path
$defaults; // will hold default field options
/*
@ashwebstudio
ashwebstudio / gist:13ecc24bc172d13b9195a98bda7d2400
Last active September 15, 2016 17:38
EDD Experiment Setup1
View gist:13ecc24bc172d13b9195a98bda7d2400
// In my header.php file right below the </head> tag
<?php if ( is_page( 'pro' ) && !edd_cart_has_discounts() ) {
<!-- Code provided by Google Experiments -->
<?php } } ?>
@ashwebstudio
ashwebstudio / gist:03fff9092b67bf162e8f4e1c1041d0a9
Last active September 15, 2016 17:40
EDD Experiment Setup 2
View gist:03fff9092b67bf162e8f4e1c1041d0a9
$current_price_int = 149;
if ( edd_cart_has_discounts() ) {
$discounts = edd_get_cart_discounts();
$discount_code = $discounts[0];
} elseif ( isset( $_GET['discount'] ) ) {
$discount_code = $_GET['discount'];
}
if ( $discount_code ) {
$new_price = edd_get_discounted_amount( $discount_code, $current_price_int );
}
@ashwebstudio
ashwebstudio / wp-nav-menu-objects-random.php
Last active November 8, 2018 05:54
WordPress: Make nav menu items appear randomly
View wp-nav-menu-objects-random.php
<?php
// You must add a class "random" to each nav menu item you wish to be randomized
add_filter( 'wp_nav_menu_objects', 'random_menu_items', 10, 2 );
function random_menu_items( $menu, $args ) {
$shuffle_array = array();
foreach ( $menu as $key => $item ) { // Loop through the menu items
if ( in_array( 'random', $item->classes ) ) { // See if this menu item has class "random"
$shuffle_array[] = $menu[ $key ]; // Put menu item into new array to be randomized
unset( $menu[ $key ] ); // Remove this from the main menu array
}
@ashwebstudio
ashwebstudio / woocommerce-acf-tabs
Created February 25, 2016 09:39
WooCommerce tabs using Advanced Custom Fields
View woocommerce-acf-tabs
// First create a field group assigned to the Product custom post type
// Make a repeater field with sub-fields "Title" (text) and "Content" (WYSIWYG)
add_filter( 'woocommerce_product_tabs', 'custom_tabs' );
function custom_tabs( $tabs ) {
global $post;
$priority = 100;
while ( has_sub_field( 'tabs', $post->ID ) ) {
$title = get_sub_field( 'title' );
@ashwebstudio
ashwebstudio / translatepress-language-cookie.php
Created April 20, 2020 21:37
TranslatePress Set Language To Cookie
View translatepress-language-cookie.php
@ashwebstudio
ashwebstudio / _log.php
Created January 28, 2023 18:36
WordPress log function
View _log.php
function _log( $message, $pre = '' ) {
if ( true === WP_DEBUG && !defined( 'DOING_CRON' ) && !defined( 'DOING_AJAX' ) ) {
if ( $pre ) {
error_log( $pre );
}
if ( is_array( $message ) || is_object( $message ) ){
error_log( print_r( $message, true ) );
} else {
error_log( $message );
}
@ashwebstudio
ashwebstudio / custom-featured-image-size.php
Last active May 4, 2023 08:04
WordPress: Make unique custom image size ONLY for featured image of a post
View custom-featured-image-size.php