Skip to content

Instantly share code, notes, and snippets.

@diggeddy
diggeddy / watch-sticky.js
Last active Aug 31, 2022
Vanilla JS Sticky Nav Observer
View watch-sticky.js
const stickyNav = document.querySelector('#site-navigation')
const mutateOptions = {
attributes: true
}
function callback(mutationList, observer) {
mutationList.forEach(function(mutation) {
if (mutation.type === 'attributes' && mutation.attributeName === 'id') {
// handle ID change
if (mutation.target.id == 'sticky-navigation') {
View Add featured image to menu iems
@diggeddy
diggeddy / featured-images.min.css
Created Apr 26, 2022
GP Featured Image CSS without zoom
View featured-images.min.css
@diggeddy
diggeddy / offside.css
Created Apr 18, 2022
GPP Offside canvas CSS with vars
View offside.css
/* offside-js 1.3.1 22-05-2016
* Minimal JavaScript kit without library dependencies to push things off-canvas using just class manipulation
* https://github.com/toomuchdesign/offside.git
*
* by Andrea Carraro
* Available under the MIT license
*/
/* Off-canvas element CSS */
:root {
View darkModeToggle.js
(function() {
var dmtoggle = document.getElementById('dmtoggle');
var body = document.body;
var darkMode = function() { body.classList.add('dark-mode'); }
var lightMode = function() { body.classList.remove('dark-mode'); }
var systemPref = undefined;
var localPrefDark = function() {
@diggeddy
diggeddy / multi-loop.php
Created Mar 4, 2022
Multiple Loop through Category Terms
View multi-loop.php
<?php
function db_multi_term_custom_loop($atts, $content = null) {
// Get all the categories
$categories = get_terms( 'category' );
ob_start();
// Loop through the $category terms
foreach ( $categories as $category ):
// new query for each category term.
$customQuery = new WP_Query(
@diggeddy
diggeddy / block-editor-59-styles.php
Created Feb 15, 2022
Add custom styles to 5.9 block editor
View block-editor-59-styles.php
add_filter( 'block_editor_settings_all', function( $editor_settings ) {
$css = 'p a {
box-shadow: 0px -1px 0px #14518F inset;
padding-bottom: 3px;
transition: all 0.6s ease 0s;
}
p a:hover {
box-shadow: 0px -2px 0px #14518F inset;
padding-bottom: 3px;
}';
@diggeddy
diggeddy / cat_list_shortcode.php
Created Jan 16, 2022
Cateogory List with description and post count
View cat_list_shortcode.php
<?php
add_shortcode('cat_listing', function($html){
$categories = get_categories();
$html = '';
foreach( $categories as $category ) {
$category_link = sprintf(
'<a href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( $category->name ),
esc_html( $category->name )
@diggeddy
diggeddy / woo-cart-count-shortcode.php
Last active Oct 18, 2021
GP Woocommerce Cart Count Shortcode
View woo-cart-count-shortcode.php
function db_custom_cart_count() {
if ( ! class_exists( 'WooCommerce' ) ) {
return;
}
if ( ! isset( WC()->cart ) ) {
return;
}
@diggeddy
diggeddy / custom-loop-shortcode-gpp.php
Last active Dec 26, 2021
Custom Loop Shortcode for displaying a GPP Content Template
View custom-loop-shortcode-gpp.php
<?php
function db_custom_loop_shortcode($atts, $content = null) {
global $post;
// Set query args
$args = array(
'post_type' => 'post',
'posts_per_page' => '3',
'post__not_in' => array( $post->ID ), // don't display current post
);
// Optional arguments for setting category term relationship on single post