Skip to content

Instantly share code, notes, and snippets.

@nathaningram
nathaningram / sort-by-meta.php
Created March 28, 2024 18:10
Sort Kadence Post Grid by Post Meta
add_filter( 'kadence_blocks_pro_posts_grid_query_args', 'sort_by_date_post_grid_order',10, 2 );
function sort_by_date_post_grid_order( $args, $attributes ) {
if ( 'POST_TYPE_SLUG_HERE' === $args['post_type'] && isset($attributes['className']) && strpos($attributes['className'], 'BLOCK_CLASS_HERE') !== false ) {
$args['meta_key'] = 'start_date';
$args['orderby'] = 'meta_value';
$args['order'] = 'ASC';
}
return $args;
}
@nathaningram
nathaningram / styles.css
Last active December 17, 2023 01:47
Optimizing Your Starter Site - CSS Samples
/********* Kadence Menu *********/
/* Hides the underline on current menu items in underline style */
.header-navigation-style-underline .current-menu-item a:after,
.header-navigation-style-underline .menu-item-has-children a:after {
display: none;
}
.header-navigation-style-underline .current-menu-item a:hover:after {
@nathaningram
nathaningram / wp-config.php
Last active November 28, 2023 19:28
Creating a Starter Site - Customized wp-config
<?php
/* Debug Options */
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_LOG', false );
/* MySQL Settings */
define( 'DB_NAME', 'database_name_here' );
define( 'DB_USER', 'username_here' );
@nathaningram
nathaningram / functions.php
Last active November 27, 2023 16:34
Creating a Starter Site - Sample functions.php
<?php
/* Enqueue child styles */
function child_enqueue_styles() {
wp_enqueue_style( 'child-theme', get_stylesheet_directory_uri() . '/style.css', array(), 100 );
}
add_action( 'wp_enqueue_scripts', 'child_enqueue_styles' );
@nathaningram
nathaningram / append-me.php
Created August 30, 2023 16:27
Append WooCommerce Product SKU to Short Description (including multiple variations)
// ADD SKUS
// Runs on update - use Quick Edit
function ni_append_sku_to_short_description($post_id) {
if ('product' !== get_post_type($post_id)) {
return;
}
$product = wc_get_product($post_id);
@nathaningram
nathaningram / cleanup-blanks.php
Last active August 14, 2023 18:32
Remove 2+ empty lines in WooCommerce Product Descriptions
// Removes empty lines in Woo Product Long + Short Descr when 2 or more occur together
// Removes empty spaces at beginning or end of descriptions
// Fires on Post Update (works with Quick Edit)
add_action('save_post_product', 'ni_clean_up_product_content', 10, 3);
function ni_clean_up_product_content($post_ID, $post, $update) {
// Check if it's an update
if ($update) {
// Get the content and short description
@nathaningram
nathaningram / sue-magic-code-from-tanya.css
Created August 3, 2023 18:20
Align Buttons to Bottom of Post Grid in Kadence
/* looped archive pages align elements */
.custom-archive-loop-item {display: flex; flex-direction: column; background-color:#fff;}
.custom-archive-loop-item .kb-row-layout-wrap {flex: 1; display: flex; flex-direction: column;}
.custom-archive-loop-item .wp-block-kadence-accordion, .custom-archive-loop-item .wp-block-kadence-advancedbtn {margin-top: auto;}
@nathaningram
nathaningram / thirdtues.php
Created July 27, 2023 19:05
Third Tuesday from Office Hours
function find_next_third_tuesday() {
$date = new DateTime();
$date->modify('first day of this month');
while ($date->format('D') != 'Tue') {
$date->modify('next day');
}
$date->modify('+2 weeks');
if($date < new DateTime()) {
$date->modify('first day of next month');
while ($date->format('D') != 'Tue') {
@nathaningram
nathaningram / sanitize-woo-descriptions.php
Created July 18, 2023 20:12
Sanitizes HMTL from Woocommerce Product Descriptions upon post Update
// Sanitizes HMTL from Woocommerce Product Descriptions upon post Update
function sanitize_product_description( $post_id ) {
// check if post is a product
if ( 'product' === get_post_type( $post_id ) ) {
// get the post object
$product = wc_get_product( $post_id );
// sanitize the descriptions
foreach ( ['description', 'short_description'] as $desc_type ) {
@nathaningram
nathaningram / alpha-settings.php
Created May 2, 2023 17:28
Sort WP Admin Settings Menu Alphabetically
// Function to sort settings menu items alphabetically
function ni_sort_settings_menu_items_alphabetically() {
global $submenu;
// Check if the settings menu exists
if (isset($submenu['options-general.php']) && is_array($submenu['options-general.php'])) {
// Sort the items under the settings menu alphabetically
usort($submenu['options-general.php'], function ($a, $b) {
// Ensure both array elements have the 0-index set and are strings
if (isset($a[0]) && isset($b[0]) && is_string($a[0]) && is_string($b[0])) {