Skip to content

Instantly share code, notes, and snippets.

View nickdavis's full-sized avatar

Nick Davis nickdavis

View GitHub Profile
@nickdavis
nickdavis / functions.php
Last active December 16, 2016 14:06
Unserialize array in PHP (from Advanced Custom Fields PRO, in this example)
<?php
/**
* Get one value from an serialized array example
*
* @link http://stackoverflow.com/questions/8192789/getting-one-value-out-of-a-serialized-array-in-php#8192803
*
* @author Nick Davis
*
* @return array
@nickdavis
nickdavis / style.css
Created November 23, 2016 09:30
Fix for Kickstart Pro v1.3.6 (and earlier) Home Row #4 post alignment issue which may occur under certain configurations of the Genesis - Featured Posts widget. If you are unsure how to tweak the CSS of your website, see: https://themevalet.com/making-wordpress-css-adjustments-without-editing-theme/
.home-row4 .post:nth-child(odd) {
margin-left: initial;
}
.home-row4 .post:nth-of-type(odd) {
clear: left;
}
.home-row4 .post:nth-of-type(even) {
margin-left: 18%;
@nickdavis
nickdavis / responsive-menu.js
Created November 19, 2016 13:02
Always show expanded menu (and hide menu pulldown button) on larger screens in Remobile Pro theme by StudioPress (regular 'mobile' menu continues to work in correct way). As seen on GenesisWP.guide at the time of writing.
jQuery(function( $ ){
// Enable responsive menu icon for mobile
$(".nav-primary .genesis-nav-menu").addClass("responsive-menu").after('<div class="responsive-menu-icon"></div>');
$(".responsive-menu-icon").click(function(){
$(".nav-primary .genesis-nav-menu").slideToggle();
});
$(window).resize(function(){
@nickdavis
nickdavis / acf-fields-flexible-content.php
Created November 10, 2016 11:05
Advanced Custom Fields > Flexible Content field example (set programatically)
<?php
add_action( 'acf/init', 'nd_acf_add_local_field_groups' );
/**
* Add Advanced Custom Fields programatically (Flexible Content field).
*
* @link https://www.advancedcustomfields.com/resources/register-fields-via-php/
* @link https://support.advancedcustomfields.com/forums/topic/register-two-locations-via-php-doesnt-work/
* @link https://support.advancedcustomfields.com/forums/topic/adding-additional-layout-to-flexible_content-field-in-child-theme/
*
@nickdavis
nickdavis / acf-fields-repeater.php
Created November 10, 2016 10:59
Advanced Custom Fields > Repeater field example (set programatically)
<?php
add_action( 'acf/init', 'nd_acf_add_local_field_groups' );
/**
* Add Advanced Custom Fields programatically (Repeater field).
*
* @link https://www.advancedcustomfields.com/resources/register-fields-via-php/
* @link https://support.advancedcustomfields.com/forums/topic/register-two-locations-via-php-doesnt-work/
* @link https://support.advancedcustomfields.com/forums/topic/adding-additional-layout-to-flexible_content-field-in-child-theme/
*
@nickdavis
nickdavis / style.css
Last active November 10, 2016 18:19
Attempt to override Kickstart Pro default backstretch effect with CSS to make image react to width of page (not tested / designed to work with a slider on the homepage)
.before-content {
height: auto;
margin-bottom: -124px;
margin-top: 0;
top: -124px;
}
.backstretch,
.backstretch img {
height: auto !important;
@nickdavis
nickdavis / style.css
Last active September 5, 2016 14:24
Extract of style.css, showing an untested example of how you might adjust the mobile logo size (and space around it) on Kickstart Pro
@media only screen and (max-width: 900px) {
.header-image .site-title a {
min-height: 95px; /* You need to allow more space for the logo if you're doing this so increase the min-height to suit */
}
.header-image .site-header .wrap {
/* background-size: 93px 48px;*/ /* Removes image resizing completely, otherwise you can uncomment it and adjust the size manually by changing the values (making sure to keep it in proportion to the original image */
}
}
@nickdavis
nickdavis / functions.php
Last active September 1, 2016 11:15
Don't do backstretch on the Kickstart Pro homepage (not tested, assumes you're coding a custom solution instead)
<?php
add_action( 'wp_enqueue_scripts', 'kickstart_enqueue_backstretch_scripts' );
// Enqueue Backstretch script and prepare images for loading
function kickstart_enqueue_backstretch_scripts() {
// Don't do any backstretching on the homepage (CUSTOM)
if ( is_front_page() ) {
return;
}
@nickdavis
nickdavis / functions.php
Last active August 17, 2016 13:49
Search for genesis-footer-widgets in your theme's functions.php file and change the number you find to the number of widget areas you would like (you may also need to tweak the CSS found in the theme's style.css file to achieve your desired layout)
<?php
add_theme_support( 'genesis-footer-widgets', 3 );
@nickdavis
nickdavis / single.php
Last active August 16, 2016 08:09
Check the width of a post's featured image in WordPress and use it to determine which image size should be displayed
<?php
function nd_featured_image_size_sniff() {
if ( ! has_post_thumbnail() ) {
return;
}
$featured_image_id = get_post_thumbnail_id( get_the_ID() );
$featured_image_metadata = wp_get_attachment_metadata( $featured_image_id );