Skip to content

Instantly share code, notes, and snippets.

View benpearson's full-sized avatar

Ben Pearson benpearson

  • Melbourne, Australia
View GitHub Profile
@benpearson
benpearson / alternate-styles.html
Last active June 24, 2021 01:58
How to add alternate styles to blocks so that they work in the WordPress admin
<style>
/* Default styles */
.section-text {
color: black;
}
.section-image {
width: 100%;
}
</style>
<div class="parent-container">
@benpearson
benpearson / PostTypeTaxonomyMirror.php
Created December 17, 2020 02:42 — forked from mishterk/PostTypeTaxonomyMirror.php
Post type/taxonomy mirror.
<?php
class PostTypeTaxonomyMirror {
private $post_type;
private $taxonomy;
// Howler
var words = new Howl({
src: ['sounds/words.mp3'],
sprite: {
all: [0, 693],
are: [693, 529],
as: [1228, 644],
at: [1871, 528],
@benpearson
benpearson / gist:f25f1d920930cd508f0b311a2fae6246
Created March 14, 2018 01:57
PHP ternary operator formatting
<?php
$image_url = get_the_post_thumbnail_url( $post->ID, 'full' ) ?: 'http://via.placeholder.com/993x556'
$image_url = get_the_post_thumbnail_url( $post->ID, 'full' )
? 'value if true'
: 'value if false';
@benpearson
benpearson / gist:d26f63be2729fd1d612e457bc77bd930
Created March 1, 2018 03:05
DT Gravity Forms validations styles (starter)
.gfield_error{
input[type="text"],
textarea {
border: 1px solid $red;
}
}
.validation_error,
@benpearson
benpearson / upcoming-events-list.php
Last active August 15, 2017 06:53
ACF Date Time Picker field: sorting and filtering posts based on the data
<?php
/**
* Events custom post type has an ACF "end_date_time" which is a Date Time Picker field.
* This code creates list of all events that have not yet ended, sorted with
* the events that are ending soonest at the top of the list.
*/
$now_date_time = new DateTime( 'now', new DateTimeZone( 'Australia/Melbourne' ) );
$upcoming_events = [];
@benpearson
benpearson / gist:9714f3353c88df6e0bb1
Created February 19, 2016 02:50
WordPress - Disable responsive images
<?php
add_filter( 'max_srcset_image_width', function (){
return 1;
} );
?>
@benpearson
benpearson / Flexslider with vertically centered images
Last active September 14, 2017 00:13
Vertically center images in slider container when image height is greater than container height (larger screens often have max height on container)
/*
Flexslider
*/
jQuery(document).ready(function($) {
// Vertically center images in slider container when image height is greater than container height (larger screens)
function verticallyCenterImages() {
var containerHeight = $('.flexslider').height();
@benpearson
benpearson / ACF - Loading images from Options page fields (for sidebar)
Last active August 29, 2015 14:04
ACF - Loading images from Options page fields (for sidebar)
<?php
// Place in sidebar.php
// Currently loading largest image size. Add text field too?
<?php if( get_field('sidebar_items', 'options') ) : ?>
<ul class="sidebar-default">
<?php while( has_sub_field('sidebar_items', 'options') ) : ?>
<li>
<?php if ( get_sub_field('title') ) : ?>
<a href="<?php the_sub_field('link'); ?>" target="<?php the_sub_field('target'); ?>" >