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 / ACF - Add sub pages to Options page
Last active August 29, 2015 14:04
ACF - Add sub pages to Options page
// Place in functions.php
/**
* Advanced custom fields - add sub pages to Options page
*/
if( function_exists('acf_add_options_sub_page') )
{
acf_add_options_sub_page( 'Sidebar' );
acf_add_options_sub_page( 'Footer' );
}
@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'); ?>" >
@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 / gist:9714f3353c88df6e0bb1
Created February 19, 2016 02:50
WordPress - Disable responsive images
<?php
add_filter( 'max_srcset_image_width', function (){
return 1;
} );
?>
@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 / 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;
@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 / search.php
Created January 7, 2025 03:57
WordPress: Search template using Search WP custom query
<?php
/**
* Search results
*
* Example of a custom query using Search WP. Note this only needed if you need a custom query.
*/
get_header();
@benpearson
benpearson / searchform.php
Created January 7, 2025 03:59
Wordpress: Default WordPress search form HTML
<?php
/**
* Default WordPress search form HTML
*
* The same HTML will be generated if you delete this partial and use get_search_form()
*/
?>
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url(home_url('/')); ?>">