Skip to content

Instantly share code, notes, and snippets.

<?php
/*
Plugin Name: Page Templater Demo
Plugin URI: http://www.damiencarbery.com/2017/09/grandchild-templates-made-easy/
Description: Demonstrate how to use pagetemplater.php and the included filters
Version: 0.1
Author: Damien Carbery
Author URI: http://www.damiencarbery.com/
*/
add_action( 'genesis_after_header', function () {
if ( is_front_page() )
unregister_sidebar( 'welcome' );
} );
@damiencarbery
damiencarbery / columns-alternating.php
Last active September 17, 2017 19:57
Using CSS Grid and the order option for an alternating layout
<?php
$args = array(
'category_name' => 'portfolio',
'post_type' => 'post',
'paged' => get_query_var( 'paged' ),
);
$wp_query = new WP_Query( $args );
if( $wp_query->have_posts() ):
while( $wp_query->have_posts() ): $wp_query->the_post();
<?php
// Use scrollreveal from https://github.com/jlmakes/scrollreveal
add_action( 'wp_footer', 'afp_scrollreveal_init' );
function afp_scrollreveal_init() {
?>
<style>
.home .widget-wrap { visibility: visible; }
.site-inner .widget-wrap, .entry-content { visibility: hidden; }
</style>
@damiencarbery
damiencarbery / specify-archives.php
Last active September 24, 2017 22:59
Move sticky posts to top of archive listings.
<?php
add_filter( 'sic_sticky_categories', 'pu_set_sticky_categories' );
function pu_set_sticky_categories( $categories ) {
// Only operate on these two categories.
$categories[] = 'edge-case-2';
$categories[] = 'media-2';
return $categories;
}
<script type="text/javascript">
jQuery(document).ready(function($) {
// Get 'body' background image and stretch it.
bg = $(document.body).css('background-image');
// Change: url("/path/to/background") to: /path/to/background
bg = bg.replace('url(','').replace(')','').replace(/"/g, '');
$(document.body).backstretch(bg);
});
</script>
@damiencarbery
damiencarbery / hide-specified-cpts.php
Created October 8, 2017 22:31
Hide Specified Custom Post Types - with a little gotcha!!
<?php
// Based on: http://markwilkinson.me/2014/09/altering-registered-post-type-args/
// Hide some of the k-boom CPTs as they will not be used.
function ce_hide_some_cpts( $post_type, $args )
{
/* Only hide the post types listed in the array. */
if (!in_array($post_type, array('audio', 'event', 'portfolio', 'video'))) {
return;
}
// Skip 'Events Manager' plugin (it has 'description' set while 'Events' CPT does not).
@damiencarbery
damiencarbery / wc-no-shipping-method-msg.php
Created October 16, 2017 10:33
WooCommerce: Change the "no shipping method available" message to minimise customer confusion.
<?php
/*
Plugin Name: WooCommerce - No shipping method message
Plugin URI: http://www.damiencarbery.com/2017/10/change-no-shipping-methods-available-message/
Description: Change the "no shipping method available" message to minimise customer confusion.
Author: Damien Carbery
Version: 0.1
*/
<?php
$images = get_field('photos');
if ($images) { ?>
<div class="images">
<?php
$alt = $images[0]['alt'];
if (empty($alt)) {
$alt = $images[0]['title'];
}
printf('<a href="%s" itemprop="image" class="main-image zoom thickbox" title="" rel="prettyPhoto[gallery] gallery"><img width="%d" height="%d" src="%s" class="attachment-shop_single size-shop_single wp-post-image" alt="%s" title="%s" /></a>',
@damiencarbery
damiencarbery / class-wc-check-availability-email.php
Last active October 25, 2017 10:32
Add custom email to WooCommerce
<?php
/**
* An email to ask the vendor to check availability of a booking.
*
* @extends \WC_Email
*
* Code copied from: https://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly