Skip to content

Instantly share code, notes, and snippets.

@diggeddy
diggeddy / category.php
Last active October 12, 2022 15:26
Nested Category archive
<?php
/**
* The template for displaying nested category pages.
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
@diggeddy
diggeddy / watch-sticky.js
Last active August 31, 2022 15:29
Vanilla JS Sticky Nav Observer
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') {
@diggeddy
diggeddy / Add featured image to menu iems
Created July 26, 2022 13:32
Menu Item Featured Image
@diggeddy
diggeddy / featured-images.min.css
Created April 26, 2022 10:00
GP Featured Image CSS without zoom
@diggeddy
diggeddy / offside.css
Created April 18, 2022 17:56
GPP Offside canvas CSS with vars
/* 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 {
@diggeddy
diggeddy / darkModeToggle.js
Created April 5, 2022 17:20
DarkMode Script
(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 March 4, 2022 17:20
Multiple Loop through Category Terms
<?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 February 15, 2022 15:14
Add custom styles to 5.9 block editor
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 January 16, 2022 11:48
Cateogory List with description and post count
<?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 October 18, 2021 13:37
GP Woocommerce Cart Count Shortcode
function db_custom_cart_count() {
if ( ! class_exists( 'WooCommerce' ) ) {
return;
}
if ( ! isset( WC()->cart ) ) {
return;
}