Skip to content

Instantly share code, notes, and snippets.

View ashwebstudio's full-sized avatar

Derek Ashauer ashwebstudio

View GitHub Profile
@ashwebstudio
ashwebstudio / block-button.js
Last active February 24, 2024 19:46
Single toggle + text attribute for core button block
/*
Adding a toggle and conditional text input to core button block
As used in Conversion Bridge, https://conversionbridgewp.com
*/
(function(wp) {
// Load dependencies.
var el = wp.element.createElement;
var Fragment = wp.element.Fragment;
var TextControl = wp.components.TextControl;
@ashwebstudio
ashwebstudio / custom-featured-image-size.php
Last active August 22, 2023 10:23
WordPress: Make unique custom image size ONLY for featured image of a post
@ashwebstudio
ashwebstudio / _log.php
Created January 28, 2023 18:36
WordPress log function
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 / translatepress-language-cookie.php
Created April 20, 2020 21:37
TranslatePress Set Language To Cookie
@ashwebstudio
ashwebstudio / wp-nav-menu-objects-random.php
Last active November 8, 2018 05:54
WordPress: Make nav menu items appear randomly
<?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 / gist:03fff9092b67bf162e8f4e1c1041d0a9
Last active September 15, 2016 17:40
EDD Experiment Setup 2
$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 / gist:13ecc24bc172d13b9195a98bda7d2400
Last active September 15, 2016 17:38
EDD Experiment Setup1
// 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 / woocommerce-acf-tabs
Created February 25, 2016 09:39
WooCommerce tabs using Advanced Custom Fields
// 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' );
<?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 / 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.
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.');
}