Skip to content

Instantly share code, notes, and snippets.

View khleomix's full-sized avatar

JC Palmes khleomix

View GitHub Profile
@khleomix
khleomix / tailwind.config.js
Last active May 1, 2023 20:54
Theme.json and Tailwind
const fs = require( 'fs' );
const path = require( 'path' );
const themeJsonPath = path.join( __dirname, 'theme.json' );
const themeJson = fs.readFileSync( themeJsonPath );
const theme = JSON.parse( themeJson );
const { palette } = theme.settings.color;
const colors = palette.reduce(( acc, item ) => {
const [color, number] = item.slug.split( '-' );
@khleomix
khleomix / acf-location-rules.php
Last active March 29, 2023 19:50
ACF Location rules for Multisite
<?php
// Display specific ACF groups on selected sites only for Multisite.
if ( is_multisite() ) :
add_filter( 'acf/location/rule_types', 'acf_location_rule_type_multisite' );
add_filter( 'acf/location/rule_values/site', 'acf_location_rule_values_multisites' );
add_filter( 'acf/location/rule_match/site', 'acf_location_rules_match_site', 10, 3 );
endif;
function acf_location_type_multisite( $choices ) {
@khleomix
khleomix / functions.php
Created March 7, 2023 18:44
Add post type slug before taxonomy slug for post link
<?php
/**
* Create the WordPress rewrite rule to handle third level slugs for videos.
*
*/
function video_cpt_generating_rule( $wp_rewrite ) {
$rules = [];
$terms = get_terms( [
'taxonomy' => 'series',
'hide_empty' => false,
@khleomix
khleomix / acf-gravity-forms-select.php
Created October 31, 2022 21:19
ACF Gravity Forms Select
<?php
/**
* Populate ACF select field options with Gravity Forms form ID
*/
function acf_populate_gf_forms_ids( $field ) {
if ( class_exists( 'GFFormsModel' ) ) {
$choices = [];
foreach ( \GFFormsModel::get_forms() as $form ) {
$choices[ $form->id ] = $form->title;
@khleomix
khleomix / taxonomy-filter.php
Last active March 16, 2022 18:51
Order posts by taxonomy
<?php
/**
* Show all posts based on taxonomy meta key.
*
* @return WP_Query $courses New WP_Query containing courses.
*/
function display_posts_taxonomy_order() {
$term_args = array(
'taxonomy' => 'discipline',
@khleomix
khleomix / smoothscroll.js
Last active March 10, 2022 19:40
Smooth Scroll to div on load
/**
* File search.js
*
* Scroll to div on load.
*
*/
const divToScroll = document.getElementById( 'scroll-here' );
document.addEventListener( 'DOMContentLoaded', function ( event ) {
@khleomix
khleomix / wistia-player.php
Created March 4, 2022 19:51
Wistia Background Video
<?php
/**
* MODULE - Wistia Player.
*
* Autoplay nuted Wistia Video in the background and remove from DOM when done.
*/
/**
* Accepts 'class','wistia_id'.
*/
@khleomix
khleomix / vimeo-video.php
Last active March 4, 2022 16:48
Vimeo Background
<?php
/**
* Shortcode to display Vimeo video.
*
* @param array $args Parameters include vimeo_id and more.
* @author JC Palmes
*/
function embed_vimeo_video( $args = [] ) {
// Set defaults.
@khleomix
khleomix / return-trim-the-content.php
Created February 25, 2022 17:17
Limit the content length and retain markup
<?php
/**
* Limit the content length.
*
* @author JC Palmes
*
* @param array $args Parameters include length and more.
*
* @return string The content.
*/
@khleomix
khleomix / acf.php
Last active February 16, 2022 22:10
Load icon files dynamically as ACF select options
<?php
/**
* Load icons dynamically into the `icon_picker` select field.
*
* @param array $field field options.
* @return array new field choices.
*
* @author JC Palmes
*/
function acf_load_icon_picker_field_choices( $field ) {